Class: Spud::BuildTools::SpudBuild::FileContext

Inherits:
Object
  • Object
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



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

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