Class: Spud::BuildTools::SpudBuild::FileContext
- Inherits:
-
Object
- Object
- Spud::BuildTools::SpudBuild::FileContext
show all
- Defined in:
- lib/build_tools/spud/file_context.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(spud, filename) ⇒ FileContext
Returns a new instance of FileContext.
8
9
10
11
12
|
# File 'lib/build_tools/spud/file_context.rb', line 8
def initialize(spud, filename)
@spud = spud
@filename = filename
@rules = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
22
23
24
|
# File 'lib/build_tools/spud/file_context.rb', line 22
def method_missing(name, *args, &block)
rule(name, *args, &block)
end
|
Instance Attribute Details
#rules ⇒ Object
Returns the value of attribute rules.
6
7
8
|
# File 'lib/build_tools/spud/file_context.rb', line 6
def rules
@rules
end
|
Instance Method Details
#prefix ⇒ Object
30
31
32
|
# File 'lib/build_tools/spud/file_context.rb', line 30
def prefix
@prefix ||= @filename == 'Spudfile' ? '' : "#{File.basename(@filename, '.rb')}."
end
|
#prefix_rule(name) ⇒ Object
26
27
28
|
# File 'lib/build_tools/spud/file_context.rb', line 26
def prefix_rule(name)
"#{prefix}#{name}"
end
|
#rule(name, *args, &block) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/build_tools/spud/file_context.rb', line 14
def rule(name, *args, &block)
files = args.select { |arg| arg.is_a?(String) }
deps = args.select { |arg| arg.is_a?(Hash) }.reduce({}) { |hash, dep| hash.merge(dep) }
name = prefix_rule(name)
@rules[name] = Rule.new(@spud, self, @filename, name, files, deps, block)
end
|