Class: Spud::BuildTools::SpudBuild::Rule
- Defined in:
- lib/build_tools/spud/rule.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(spud, file_context, filename, name, files, deps, block) ⇒ Rule
constructor
A new instance of Rule.
- #invoke(*args, **kwargs) ⇒ Object
- #keyword_params ⇒ Object
-
#positional_params ⇒ Object
Params.
Constructor Details
#initialize(spud, file_context, filename, name, files, deps, block) ⇒ Rule
Returns a new instance of Rule.
11 12 13 14 15 16 17 18 19 |
# File 'lib/build_tools/spud/rule.rb', line 11 def initialize(spud, file_context, filename, name, files, deps, block) @spud = spud @file_context = file_context @filename = filename @name = name @files = files @deps = deps @block = block end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/build_tools/spud/rule.rb', line 9 def filename @filename end |
Instance Method Details
#invoke(*args, **kwargs) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/build_tools/spud/rule.rb', line 21 def invoke(*args, **kwargs) raise Spud::Error, "'#{@name}' is up to date" if up_to_date? missing = positional_params.length - args.length if missing > 0 names = positional_params.map { |name| "'#{name}'" }.join(', ') arguments = missing > 1 ? 'arguments' : 'argument' raise Spud::Error, "invocation of '#{@name}' missing required #{arguments} #{names}" end return RuleContext.new(@spud, @file_context).instance_exec(*args, &@block) unless key_params? begin RuleContext.new(@spud, @file_context).instance_exec(*args, **kwargs, &@block) rescue ArgumentError => e raise Spud::Error, "invocation of '#{@name}' with #{e.}" end end |
#keyword_params ⇒ Object
45 46 47 |
# File 'lib/build_tools/spud/rule.rb', line 45 def keyword_params @keyword_params ||= params.select { |p| p.first == :key }.map(&:last) end |
#positional_params ⇒ Object
Params
41 42 43 |
# File 'lib/build_tools/spud/rule.rb', line 41 def positional_params @positional_params ||= params.select { |p| p.first == :req }.map(&:last) end |