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.
-
#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
- #dynamic? ⇒ Boolean
- #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.
25 26 27 28 29 30 31 32 |
# File 'lib/build/rule.rb', line 25 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.
34 35 36 |
# File 'lib/build/rule.rb', line 34 def direction @direction end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/build/rule.rb', line 35 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
37 38 39 |
# File 'lib/build/rule.rb', line 37 def @options end |
Instance Method Details
#applicable?(arguments) ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/build/rule.rb', line 60 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
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/build/rule.rb', line 74 def compute(arguments, scope) if implicit? # Can be replaced if supplied: arguments[@name] || scope.instance_exec(arguments, &@dynamic) elsif dynamic? # Argument is optional: scope.instance_exec(arguments[@name], arguments, &@dynamic) else arguments[@name] end end |
#dynamic? ⇒ Boolean
47 48 49 |
# File 'lib/build/rule.rb', line 47 def dynamic? @dynamic != nil end |
#implicit? ⇒ Boolean
51 52 53 |
# File 'lib/build/rule.rb', line 51 def implicit? dynamic? and @options[:implicit] end |
#input? ⇒ Boolean
39 40 41 |
# File 'lib/build/rule.rb', line 39 def input? @direction == :input end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/build/rule.rb', line 86 def inspect "#{direction}:#{@name} (#{.inspect})" end |
#optional? ⇒ Boolean
Optional parameters are those that are either defined as optional or implicit.
56 57 58 |
# File 'lib/build/rule.rb', line 56 def optional? @options[:optional] || implicit? end |
#output? ⇒ Boolean
43 44 45 |
# File 'lib/build/rule.rb', line 43 def output? @direction == :output end |