Class: Spud::BuildTools::SpudBuild::FileContext
- Inherits:
-
Object
- Object
- Spud::BuildTools::SpudBuild::FileContext
- Defined in:
- lib/build_tools/spud/file_context.rb
Instance Attribute Summary collapse
-
#__rules ⇒ Object
readonly
Returns the value of attribute __rules.
Instance Method Summary collapse
-
#initialize(spud, filename) ⇒ FileContext
constructor
A new instance of FileContext.
- #method_missing(name, *args, &block) ⇒ Object
- #require_relative(name) ⇒ Object
- #rule(name, *args, &block) ⇒ Object
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
28 29 30 |
# File 'lib/build_tools/spud/file_context.rb', line 28 def method_missing(name, *args, &block) rule(name, *args, &block) end |
Instance Attribute Details
#__rules ⇒ Object (readonly)
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
#require_relative(name) ⇒ Object
14 15 16 |
# File 'lib/build_tools/spud/file_context.rb', line 14 def require_relative(name) require(name) end |
#rule(name, *args, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/build_tools/spud/file_context.rb', line 18 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) } prefix = @__filename == 'Spudfile' ? '' : "#{File.basename(@__filename, '.rb')}." name = "#{prefix}#{name}" @__rules[name] = Rule.new(@__spud, self, @__filename, name, files, deps, block) end |