Class: Schematic::Generator::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/schematic/generator/sandbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Sandbox

Returns a new instance of Sandbox.



9
10
11
12
13
14
15
# File 'lib/schematic/generator/sandbox.rb', line 9

def initialize(klass)
  @klass = klass
  @ignored_elements ||= Hash.new([])
  @added_elements ||= {}
  @required_elements ||= []
  @non_required_elements ||= []
end

Instance Attribute Details

#added_elementsObject

Returns the value of attribute added_elements.



7
8
9
# File 'lib/schematic/generator/sandbox.rb', line 7

def added_elements
  @added_elements
end

#ignored_elementsObject

Returns the value of attribute ignored_elements.



7
8
9
# File 'lib/schematic/generator/sandbox.rb', line 7

def ignored_elements
  @ignored_elements
end

#non_required_elementsObject

Returns the value of attribute non_required_elements.



7
8
9
# File 'lib/schematic/generator/sandbox.rb', line 7

def non_required_elements
  @non_required_elements
end

#required_elementsObject

Returns the value of attribute required_elements.



7
8
9
# File 'lib/schematic/generator/sandbox.rb', line 7

def required_elements
  @required_elements
end

Instance Method Details

#add(*args) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/schematic/generator/sandbox.rb', line 49

def add(*args)
  name = args.shift
  if name.is_a? Hash
    added_elements[name.keys.first] = name.values.first
  else
    added_elements[name] = nil
  end
end

#generate_xsd(builder, klass, include_collection, options, exclude) ⇒ Object



34
35
36
37
# File 'lib/schematic/generator/sandbox.rb', line 34

def generate_xsd(builder, klass, include_collection, options, exclude)
  xsd_generator.options = options
  xsd_generator.generate(builder, klass, include_collection, exclude)
end

#ignore(*fields) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/schematic/generator/sandbox.rb', line 39

def ignore(*fields)
  if fields[0].is_a?(Hash)
    fields[0].each do |key, value|
      ignored_elements[key.to_sym] = value
    end
  else
    fields.each { |field| ignored_elements[field] = nil }
  end
end

#not_required(*fields) ⇒ Object



62
63
64
# File 'lib/schematic/generator/sandbox.rb', line 62

def not_required(*fields)
  fields.each { |field| non_required_elements << field }
end

#required(*fields) ⇒ Object



58
59
60
# File 'lib/schematic/generator/sandbox.rb', line 58

def required(*fields)
  fields.each { |field| required_elements << field }
end

#root(name) ⇒ Object



66
67
68
# File 'lib/schematic/generator/sandbox.rb', line 66

def root(name)
  xsd_generator.names.root = name
end

#run(&block) ⇒ Object



17
18
19
# File 'lib/schematic/generator/sandbox.rb', line 17

def run(&block)
  instance_eval &block
end

#to_xsd(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/schematic/generator/sandbox.rb', line 25

def to_xsd(options = {})
  output = ''
  builder = Builder::XmlMarkup.new(:target => output, :indent => 2)
  xsd_generator.options = options
  xsd_generator.header(builder)
  xsd_generator.schema(builder)
  output
end

#xsd_generatorObject



21
22
23
# File 'lib/schematic/generator/sandbox.rb', line 21

def xsd_generator
  @xsd_generator ||= Schematic::Generator::Xsd.new(@klass)
end