Class: RootCleanroom

Inherits:
BaseCleanroom show all
Includes:
Utils
Defined in:
lib/roundtrip_xml/root_cleanroom.rb

Overview

addes the ‘define` and `use_file` method to a cleanroom. Only used when evaluating a root file

Constant Summary

Constants included from Utils

Utils::UNDEFINED_PARAM, Utils::VAR_SUFIX

Instance Attribute Summary

Attributes inherited from BaseCleanroom

#show_undefined_params, #value_holder

Instance Method Summary collapse

Methods included from Utils

included, #name_to_sym, #new_roxml_class

Methods inherited from BaseCleanroom

#_matcher, #_metadata, #append_child_modifications, #create_method, #expand, #expose_attr_accessors, #get_el, #inherit_properties, #initialize

Constructor Details

This class inherits a constructor from BaseCleanroom

Instance Method Details

#apply_template(name, &block) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
# File 'lib/roundtrip_xml/root_cleanroom.rb', line 45

def apply_template(name, &block)
  clazz = @runtime.fetch name
  raise ArgumentError, "#{name} must extend #{get_el.class.class_name}" unless clazz.ancestors.any? {|p| p == get_el.class}

  expanded_template = expand clazz, &block

  @el = expanded_template
end

#define(name, parent, *params, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/roundtrip_xml/root_cleanroom.rb', line 6

def define(name, parent, *params, &block)
  parent_class = @runtime.fetch parent
  new_class = new_roxml_class(name, parent_class) do
    self.instance_variable_set :@class_name, name
    # simply using @@params is referring to `AContainer`
    # hash = self.class_variable_defined?(:@@block) ? self.class_variable_get(:@@block) : {}
    # hash[name] = block
    self.instance_variable_set :@is_subclass, true
    self.instance_variable_set(:@block, block)
    params.each do |param|
      plain_accessor param
    end

    parent_class.plain_accessors.each do |accessor|
      plain_accessor accessor
    end

    def process
      proc = self.class.instance_variable_get(:@block)#[self.class.instance_variable_get(:@class_name)]
      if self.class.superclass.respond_to? :process
        [proc].concat self.class.superclass.process
      else
        [proc]
      end
    end
    def self.process
      proc = self.instance_variable_get(:@block)
      if self.superclass.respond_to? :process
        [proc].concat self.superclass.process
      else
        [proc]
      end
    end

  end
  @runtime.add_class name, new_class
end

#use_file(path) ⇒ Object



56
57
58
# File 'lib/roundtrip_xml/root_cleanroom.rb', line 56

def use_file(path)
  self.evaluate_file(path)
end