lib/eco/api/session/batch/base_policy.rb in eco-helpers-1.5.1 vs lib/eco/api/session/batch/base_policy.rb in eco-helpers-1.5.2
- old
+ new
@@ -1,10 +1,10 @@
module Eco
module API
class Session
class Batch
- # Helper class to build a hiearchical model of policies
+ # Helper class to build a hierarchical model of policies
# @example Usage:
# class PolicyModel < Eco::API::Session::Batch::BasePolicy
# MODEL = {attr1: ["prop1a", "prop1b", {"prop1c": ["prop1c1"]}]}
# self.model = MODEL
# policy_attrs *model_attrs
@@ -35,11 +35,11 @@
klass.policy_attrs *klass.model_attrs
end
end
# Attributes of this level of the model that should be included
- # @param attr [Symbol, String] each of the subpolicies of the model that should be available
+ # @param attrs [Array<Symbol>, Array<String>] each of the subpolicies of the model that should be available
def policy_attrs(*attrs)
attrs = attrs.map(&:to_sym)
attrs.each do |attr|
method = attr.to_s.freeze
@@ -80,18 +80,18 @@
"#{@_parent.attr(as_namespace: true)}:#{@attr}"
end
# @note if there's no `min` defined, it always returns `true`
# @param value [Integer] value to check if it's in the minimum required
- # @retrun [Boolen] `true` if `value` is grater or equal to `min`
+ # @return [Boolen] `true` if `value` is grater or equal to `min`
def min?(value)
!min || !value|| (min <= value)
end
# @note if there's no `max` defined, it always returns `true`
# @param value [Integer] value to check if it's in the maximum allowed
- # @retrun [Boolen] `true` if `value` is lesser or equal to `min`
+ # @return [Boolen] `true` if `value` is lesser or equal to `min`
def max?(value)
!max || !value || (max >= value)
end
# return [Integer] number of declared subpolicies
@@ -107,11 +107,11 @@
# @return [Boolean] `true` if there are active subpolicies, `false` otherwise
def subpolicies?
!empty?
end
- def each(params: {}, &block)
+ def each(&block)
return to_enum(:each) unless block
items.each(&block)
end
# @return [Array<Eco::API::Session::Batch::BasePolicy>] the active subpolicies
@@ -210,10 +210,11 @@
def model_attr?(hash)
hash.key?(self.attr) || hash.key?(self.attr.to_s)
end
def model_attr(hash)
- hash[self.attr] || hash[self.attr.to_s] if model_attr?(hash)
+ return hash[self.attr] if hash.key?(self.attr)
+ hash[self.attr.to_s] if model_attr?(hash)
end
private
def model_to_hash(model)