Skip to content

Commit

Permalink
Update dependencies to tram-policy v2.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
nepalez committed Jan 4, 2018
1 parent 60c93fb commit 323cc2a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion evil-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "dry-initializer", "~> 2.1"
gem.add_runtime_dependency "mime-types", "~> 3.1"
gem.add_runtime_dependency "rack", "~> 2"
gem.add_runtime_dependency "tram-policy", "~> 0.2.2", "<= 0.2.3"
gem.add_runtime_dependency "tram-policy", "~> 0.2.3"

gem.add_development_dependency "rake", ">= 10"
gem.add_development_dependency "rspec", "~> 3.0"
Expand Down
32 changes: 19 additions & 13 deletions lib/evil/client/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,11 @@ def validate(&block)
# @param [Evil::Client::Model] other
# @return [self]
#
# rubocop: disable Metrics/AbcSize
def extend(other)
return super if other.instance_of? Module

unless other.ancestors.include? Evil::Client::Model
raise TypeError, "#{other} is not a subclass of Evil::Client::Model"
end

other.dry_initializer.options.each do |definition|
option definition.source, definition.options
end

other.lets.each { |key, block| let(key, &block) }
other.policy.all.each { |validator| policy.local << validator }
validate_model other
extend_model other
end
# rubocop: enable Metrics/AbcSize

# Model instance constructor
#
Expand All @@ -119,6 +108,23 @@ def in_english(&block)
ensure
I18n.available_locales = available_locales
end

def validate_model(other)
return if other.ancestors.include? Evil::Client::Model
raise TypeError, "#{other} is not a subclass of Evil::Client::Model"
end

def extend_model(other)
other.dry_initializer.options.each do |definition|
option definition.source, definition.options
end

other.lets.each { |key, block| let(key, &block) }

other.policy.validators.each do |validator|
policy.local_validators << validator
end
end
end
end
end
8 changes: 5 additions & 3 deletions lib/evil/client/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ def name
alias_method :to_sym, :name
alias_method :inspect, :name

private

# Redefines translation scope for the policy
#
# @return[Array<Symbol>]
#
def scope
@scope ||= %i[evil client errors] << \
Tram::Policy::Inflector.underscore(model.to_s)
Tram::Policy::Inflector.underscore(model.to_s).to_sym
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/fixtures/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ en:
token_present: "To update user id:%{id} you must provide a token"
name_present: "The user has no name"
test/client:
valid_credentials: You should set either token or password to authenticate the client
valid_credentials: &vc You should set either token or password to authenticate the client
crm:
users:
valid_credentials: *vc
fetch:
valid_credentials: *vc
filter:
filter_given: You should define some filter with either name, email, or id
test/model:
Expand Down

0 comments on commit 323cc2a

Please sign in to comment.