Class: ParamsReady::Helpers::UsageRule

Inherits:
Object
  • Object
show all
Defined in:
lib/params_ready/helpers/usage_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_definitionObject (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

#ruleObject (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

Raises:



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
    message = "Can't merge incompatible rules: #{parameter_definition.name}/#{other.parameter_definition.name}"
    raise ParamsReadyError, message
  end

  rule = self.rule.merge(other.rule)
  UsageRule.new(parameter_definition, rule)
end

#nameObject



18
19
20
# File 'lib/params_ready/helpers/usage_rule.rb', line 18

def name
  parameter_definition.name
end

#valid_for?(method) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/params_ready/helpers/usage_rule.rb', line 14

def valid_for?(method)
  @rule.include? method
end