Class: Smelter::DefinitionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/smelter/definition_proxy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script_id) ⇒ DefinitionProxy

Returns a new instance of DefinitionProxy.



6
7
8
# File 'lib/smelter/definition_proxy.rb', line 6

def initialize(script_id)
  @script_id = script_id
end

Instance Attribute Details

#extensions(glob) ⇒ Object (readonly)

Returns the value of attribute extensions.



4
5
6
# File 'lib/smelter/definition_proxy.rb', line 4

def extensions
  @extensions
end

#script_idObject (readonly)

Returns the value of attribute script_id.



3
4
5
# File 'lib/smelter/definition_proxy.rb', line 3

def script_id
  @script_id
end

Class Method Details

.extension_classObject



41
42
43
# File 'lib/smelter/definition_proxy.rb', line 41

def self.extension_class
  @extension_class
end

.extension_class=(val) ⇒ Object



37
38
39
# File 'lib/smelter/definition_proxy.rb', line 37

def self.extension_class=(val)
  @extension_class = val
end

Instance Method Details

#extension(&block) ⇒ Object



33
34
35
# File 'lib/smelter/definition_proxy.rb', line 33

def extension(&block)
  self.class.extension_class.register(script_id, &block)
end

#script(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/smelter/definition_proxy.rb', line 14

def script(&block)
  runner = ScriptRunner.new

  # Define all locally registered extensions on this runner instance
  if self.class.extension_class
    self.class.extension_class.registry.each_pair do |extension_id, block|
      next unless matches_extensions_glob?(extension_id)
      runner.instance_eval(&block)
    end
  end

  # Set up runner instance for use
  if block_given?
    runner.instance_eval(&block)
  end

  runner
end