depp now rubocop ready

This commit is contained in:
Priit Tark 2015-04-07 17:02:47 +03:00
parent c0b6604ba9
commit ce52e6e097
6 changed files with 23 additions and 32 deletions

View file

@ -17,11 +17,8 @@ end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake' load 'rails/tasks/engine.rake'
load 'rails/tasks/statistics.rake' load 'rails/tasks/statistics.rake'
Bundler::GemHelper.install_tasks Bundler::GemHelper.install_tasks
require 'rake/testtask' require 'rake/testtask'
@ -33,5 +30,4 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false t.verbose = false
end end
task default: :test task default: :test

View file

@ -10,7 +10,7 @@ module Depp
helper_method :depp_current_user helper_method :depp_current_user
rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |exception| rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |_exception|
redirect_to login_url, alert: t(:no_connection_to_registry) redirect_to login_url, alert: t(:no_connection_to_registry)
end end

View file

@ -11,12 +11,15 @@ module Depp
DISCLOSURE_TYPES = [DISABLED, '1', '0'] DISCLOSURE_TYPES = [DISABLED, '1', '0']
TYPES = %w( bic priv birthday ) TYPES = %w( bic priv birthday )
SELECTION_TYPES = [ SELECTION_TYPES = [
[ 'Business code', 'bic' ], ['Business code', 'bic'],
[ 'Personal identification code', 'priv' ], ['Personal identification code', 'priv'],
[ 'Birthday', 'birthday' ] ['Birthday', 'birthday']
] ]
class << self class << self
attr_reader :epp_xml, :user
# rubocop: disable Metrics/MethodLength
def new_from_params(params) def new_from_params(params)
new( new(
id: params[:code], id: params[:code],
@ -36,9 +39,10 @@ module Depp
city: params[:city], city: params[:city],
zip: params[:zip], zip: params[:zip],
state: params[:state], state: params[:state],
country_code: params[:country_code], country_code: params[:country_code]
) )
end end
# rubocop: enable Metrics/MethodLength
def find_by_id(id) def find_by_id(id)
data = info_xml(id) data = info_xml(id)
@ -77,14 +81,6 @@ module Depp
@epp_xml = EppXml::Contact.new(cl_trid_prefix: user.tag) @epp_xml = EppXml::Contact.new(cl_trid_prefix: user.tag)
end end
def epp_xml
@epp_xml
end
def user
@user
end
def info_xml(id, password = nil) def info_xml(id, password = nil)
xml = epp_xml.info( xml = epp_xml.info(
id: { value: id }, id: { value: id },
@ -140,7 +136,7 @@ module Depp
end end
end end
def initialize(attributes={}) def initialize(attributes = {})
super super
self.country_code = 'EE' if country_code.blank? self.country_code = 'EE' if country_code.blank?
self.ident_type = 'bic' if ident_type.blank? self.ident_type = 'bic' if ident_type.blank?
@ -172,6 +168,7 @@ module Depp
handle_errors(data) handle_errors(data)
end end
# rubocop: disable Metrics/MethodLength
def update_attributes(params) def update_attributes(params)
self.ident_country_code = params[:ident_country_code] self.ident_country_code = params[:ident_country_code]
self.ident_type = params[:ident_type] self.ident_type = params[:ident_type]
@ -215,6 +212,7 @@ module Depp
data = Depp::Contact.user.request(update_xml) data = Depp::Contact.user.request(update_xml)
handle_errors(data) handle_errors(data)
end end
# rubocop: enable Metrics/MethodLength
def delete def delete
delete_xml = Contact.epp_xml.delete( delete_xml = Contact.epp_xml.delete(
@ -275,17 +273,13 @@ module Depp
def handle_errors(data) def handle_errors(data)
data.css('result').each do |x| data.css('result').each do |x|
success_codes = %(1000, 1300, 1301) success_codes = %(1000, 1300, 1301)
next if success_codes.include?(x['code'])
unless success_codes.include?(x['code']) message = "#{x.css('msg').text} #{x.css('value').text}"
message = "#{x.css('msg').text} #{x.css('value').text}" attr = message.split('[').last.strip.sub(']', '') if message.include?('[')
attr = :base if attr.nil?
attr = message.split('[').last.strip.sub(']','') if message.include?('[') attr = 'phone' if attr == 'voice'
errors.add(attr, message)
attr = :base if attr.nil?
attr = 'phone' if attr == 'voice'
errors.add(attr, message)
end
end end
errors.blank? errors.blank?
end end

View file

@ -1,5 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. # This command will automatically be run
# when you run "rails" with Rails 4 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__) ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/depp/engine', __FILE__) ENGINE_PATH = File.expand_path('../../lib/depp/engine', __FILE__)

View file

@ -1,4 +1,4 @@
$:.push File.expand_path("../lib", __FILE__) $LOAD_PATH.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version: # Maintain your gem's version:
require "depp/version" require "depp/version"

View file

@ -6,10 +6,10 @@ class SortedCountry
include ActionView::Helpers include ActionView::Helpers
def all_options(selected = nil) def all_options(selected = nil)
quick_options = options_for_select(quick_list + [['---','']], selected) quick_options = options_for_select(quick_list + [['---', '']], selected)
# no double select # no double select
selected = quick_list.map{ |c| c.second }.include?(selected) ? '' : selected selected = quick_list.map(&:second).include?(selected) ? '' : selected
all_options = options_for_select(all_sorted_truncated, selected) all_options = options_for_select(all_sorted_truncated, selected)
quick_options + all_options quick_options + all_options