Class: Build::Rule::Parameter
- Inherits:
-
Object
- Object
- Build::Rule::Parameter
- Defined in:
- lib/build/rule.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#dynamic ⇒ Object
readonly
Returns the value of attribute dynamic.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #applicable?(arguments) ⇒ Boolean
- #compute(arguments, scope) ⇒ Object
-
#default? ⇒ Boolean
Do we have a default value for this parameter?.
- #dynamic? ⇒ Boolean
-
#eql?(other) ⇒ Boolean
TODO fix implementation.
- #hash ⇒ Object
- #implicit? ⇒ Boolean
-
#initialize(direction, name, options = {}, &block) ⇒ Parameter
constructor
A new instance of Parameter.
- #input? ⇒ Boolean
- #inspect ⇒ Object
-
#optional? ⇒ Boolean
Optional parameters are those that are either defined as optional or implicit.
- #output? ⇒ Boolean
Constructor Details
#initialize(direction, name, options = {}, &block) ⇒ Parameter
Returns a new instance of Parameter.
33 34 35 36 37 38 39 40 |
# File 'lib/build/rule.rb', line 33 def initialize(direction, name, = {}, &block) @direction = direction @name = name @options = @dynamic = block_given? ? Proc.new(&block) : nil end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
42 43 44 |
# File 'lib/build/rule.rb', line 42 def direction @direction end |
#dynamic ⇒ Object (readonly)
Returns the value of attribute dynamic.
46 47 48 |
# File 'lib/build/rule.rb', line 46 def dynamic @dynamic end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
43 44 45 |
# File 'lib/build/rule.rb', line 43 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
45 46 47 |
# File 'lib/build/rule.rb', line 45 def @options end |
Instance Method Details
#applicable?(arguments) ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/build/rule.rb', line 74 def applicable? arguments value = arguments.fetch(@name) do # Value couldn't be found, if it wasn't optional, this parameter didn't apply: return optional? end # If a pattern is provided, we must match it. if pattern = @options[:pattern] return Array(value).all? {|item| pattern.match(item)} end return true end |
#compute(arguments, scope) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/build/rule.rb', line 88 def compute(arguments, scope) if implicit? # Can be replaced if supplied: arguments[@name] || scope.instance_exec(arguments, &@dynamic) || @options[:default] elsif dynamic? # Argument is optional: scope.instance_exec(arguments[@name], arguments, &@dynamic) || @options[:default] elsif arguments.key?(@name) arguments[@name] else @options[:default] end end |
#default? ⇒ Boolean
Do we have a default value for this parameter?
61 62 63 |
# File 'lib/build/rule.rb', line 61 def default? @options.key?(:default) end |
#dynamic? ⇒ Boolean
56 57 58 |
# File 'lib/build/rule.rb', line 56 def dynamic? @dynamic != nil end |
#eql?(other) ⇒ Boolean
TODO fix implementation
107 108 109 |
# File 'lib/build/rule.rb', line 107 def eql? other other.kind_of?(self.class) and @direction.eql?(other.direction) and @name.eql?(other.name) and @options.eql?(other.) # and @dynamic == other.dynamic end |
#hash ⇒ Object
102 103 104 |
# File 'lib/build/rule.rb', line 102 def hash [self.class, @direction, @name, @options].hash end |
#implicit? ⇒ Boolean
65 66 67 |
# File 'lib/build/rule.rb', line 65 def implicit? dynamic? and @options[:implicit] end |
#input? ⇒ Boolean
48 49 50 |
# File 'lib/build/rule.rb', line 48 def input? @direction == :input end |
#inspect ⇒ Object
111 112 113 |
# File 'lib/build/rule.rb', line 111 def inspect "#{direction}:#{@name} (#{.inspect})" end |
#optional? ⇒ Boolean
Optional parameters are those that are either defined as optional or implicit.
70 71 72 |
# File 'lib/build/rule.rb', line 70 def optional? @options[:optional] || implicit? || default? end |
#output? ⇒ Boolean
52 53 54 |
# File 'lib/build/rule.rb', line 52 def output? @direction == :output end |