Class: Spud::BuildTools::SpudBuild::Rule

Inherits:
BuildRule
  • Object
show all
Defined in:
lib/build_tools/spud/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

Raises:



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.message}"
  end
end

#keyword_paramsObject



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_paramsObject

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