Class: ParamsReady::Helpers::UsageRule
- Inherits:
-
Object
- Object
- ParamsReady::Helpers::UsageRule
- Defined in:
- lib/params_ready/helpers/usage_rule.rb
Instance Attribute Summary collapse
-
#parameter_definition ⇒ Object
readonly
Returns the value of attribute parameter_definition.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
-
#initialize(parameter_definition, rule = :all) ⇒ UsageRule
constructor
A new instance of UsageRule.
- #merge(other) ⇒ Object
- #name ⇒ Object
- #valid_for?(method) ⇒ Boolean
Constructor Details
#initialize(parameter_definition, rule = :all) ⇒ UsageRule
Returns a new instance of UsageRule.
8 9 10 11 12 |
# File 'lib/params_ready/helpers/usage_rule.rb', line 8 def initialize(parameter_definition, rule = :all) @parameter_definition = parameter_definition @rule = ParamsReady::Helpers::Rule(rule) freeze end |
Instance Attribute Details
#parameter_definition ⇒ Object (readonly)
Returns the value of attribute parameter_definition.
6 7 8 |
# File 'lib/params_ready/helpers/usage_rule.rb', line 6 def parameter_definition @parameter_definition end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
6 7 8 |
# File 'lib/params_ready/helpers/usage_rule.rb', line 6 def rule @rule end |
Instance Method Details
#merge(other) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/params_ready/helpers/usage_rule.rb', line 22 def merge(other) return self if other.nil? raise ParamsReadyError, "Can't merge into #{other.class.name}" unless other.is_a? UsageRule unless parameter_definition == other.parameter_definition = "Can't merge incompatible rules: #{parameter_definition.name}/#{other.parameter_definition.name}" raise ParamsReadyError, end rule = self.rule.merge(other.rule) UsageRule.new(parameter_definition, rule) end |
#name ⇒ Object
18 19 20 |
# File 'lib/params_ready/helpers/usage_rule.rb', line 18 def name parameter_definition.name end |
#valid_for?(method) ⇒ Boolean
14 15 16 |
# File 'lib/params_ready/helpers/usage_rule.rb', line 14 def valid_for?(method) @rule.include? method end |