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
-
#default? ⇒ Boolean
Do we have a default value for this parameter?.
- #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.
33 34 35 36 37 38 39 40 |
# File 'lib/build/rule.rb', line 33 def initialize(direction, name, = {}, &block) @direction = direction @name = name = @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 |
#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 end |
Instance Method Details
#applicable?(arguments) ⇒ Boolean
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/build/rule.rb', line 73 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 = [:pattern] return Array(value).all? {|item| pattern.match(item)} end return true end |
#compute(arguments, scope) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/build/rule.rb', line 87 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 || [:default] end |
#default? ⇒ Boolean
Do we have a default value for this parameter?
60 61 62 |
# File 'lib/build/rule.rb', line 60 def default? .key?(:default) end |
#dynamic? ⇒ Boolean
55 56 57 |
# File 'lib/build/rule.rb', line 55 def dynamic? @dynamic != nil end |
#implicit? ⇒ Boolean
64 65 66 |
# File 'lib/build/rule.rb', line 64 def implicit? dynamic? and [:implicit] end |
#input? ⇒ Boolean
47 48 49 |
# File 'lib/build/rule.rb', line 47 def input? @direction == :input end |
#inspect ⇒ Object
99 100 101 |
# File 'lib/build/rule.rb', line 99 def inspect "#{direction}:#{@name} (#{options.inspect})" end |
#optional? ⇒ Boolean
Optional parameters are those that are either defined as optional or implicit.
69 70 71 |
# File 'lib/build/rule.rb', line 69 def optional? [:optional] || implicit? || default? end |
#output? ⇒ Boolean
51 52 53 |
# File 'lib/build/rule.rb', line 51 def output? @direction == :output end |