Class: Schematic::Generator::Sandbox
- Inherits:
-
Object
- Object
- Schematic::Generator::Sandbox
- Defined in:
- lib/schematic/generator/sandbox.rb
Instance Attribute Summary collapse
-
#added_elements ⇒ Object
Returns the value of attribute added_elements.
-
#ignored_elements ⇒ Object
Returns the value of attribute ignored_elements.
-
#non_required_elements ⇒ Object
Returns the value of attribute non_required_elements.
-
#required_elements ⇒ Object
Returns the value of attribute required_elements.
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #generate_xsd(builder, klass, include_collection, options, exclude) ⇒ Object
- #ignore(*fields) ⇒ Object
-
#initialize(klass) ⇒ Sandbox
constructor
A new instance of Sandbox.
- #not_required(*fields) ⇒ Object
- #required(*fields) ⇒ Object
- #root(name) ⇒ Object
- #run(&block) ⇒ Object
- #to_xsd(options = {}) ⇒ Object
- #xsd_generator ⇒ Object
Constructor Details
#initialize(klass) ⇒ Sandbox
Returns a new instance of Sandbox.
6 7 8 9 10 11 12 |
# File 'lib/schematic/generator/sandbox.rb', line 6 def initialize(klass) @klass = klass @ignored_elements ||= Hash.new([]) @added_elements ||= {} @required_elements ||= [] @non_required_elements ||= [] end |
Instance Attribute Details
#added_elements ⇒ Object
Returns the value of attribute added_elements.
4 5 6 |
# File 'lib/schematic/generator/sandbox.rb', line 4 def added_elements @added_elements end |
#ignored_elements ⇒ Object
Returns the value of attribute ignored_elements.
4 5 6 |
# File 'lib/schematic/generator/sandbox.rb', line 4 def ignored_elements @ignored_elements end |
#non_required_elements ⇒ Object
Returns the value of attribute non_required_elements.
4 5 6 |
# File 'lib/schematic/generator/sandbox.rb', line 4 def non_required_elements @non_required_elements end |
#required_elements ⇒ Object
Returns the value of attribute required_elements.
4 5 6 |
# File 'lib/schematic/generator/sandbox.rb', line 4 def required_elements @required_elements end |
Instance Method Details
#add(*args) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/schematic/generator/sandbox.rb', line 46 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
31 32 33 34 |
# File 'lib/schematic/generator/sandbox.rb', line 31 def generate_xsd(builder, klass, include_collection, , exclude) xsd_generator. = xsd_generator.generate(builder, klass, include_collection, exclude) end |
#ignore(*fields) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/schematic/generator/sandbox.rb', line 36 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
59 60 61 |
# File 'lib/schematic/generator/sandbox.rb', line 59 def not_required(*fields) fields.each { |field| non_required_elements << field } end |
#required(*fields) ⇒ Object
55 56 57 |
# File 'lib/schematic/generator/sandbox.rb', line 55 def required(*fields) fields.each { |field| required_elements << field } end |
#root(name) ⇒ Object
63 64 65 |
# File 'lib/schematic/generator/sandbox.rb', line 63 def root(name) xsd_generator.names.root = name end |
#run(&block) ⇒ Object
14 15 16 |
# File 'lib/schematic/generator/sandbox.rb', line 14 def run(&block) instance_eval &block end |
#to_xsd(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/schematic/generator/sandbox.rb', line 22 def to_xsd( = {}) output = "" builder = Builder::XmlMarkup.new(:target => output, :indent => 2) xsd_generator. = xsd_generator.header(builder) xsd_generator.schema(builder) output end |