Class: ScaffoldParser::Scaffolders::XSD::Parser::Handlers::Module
- Inherits:
-
Object
- Object
- ScaffoldParser::Scaffolders::XSD::Parser::Handlers::Module
- Includes:
- Utils
- Defined in:
- lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb
Instance Attribute Summary collapse
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#inherit_from ⇒ Object
Returns the value of attribute inherit_from.
-
#methods ⇒ Object
Returns the value of attribute methods.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#initialize(source = nil, methods = []) {|_self| ... } ⇒ Module
constructor
A new instance of Module.
- #name_with_prefix ⇒ Object
- #schema(_) ⇒ Object
- #to_builder_s ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
#indent, #indent_string, #single_quote, #wrap_in_namespace
Constructor Details
#initialize(source = nil, methods = []) {|_self| ... } ⇒ Module
Returns a new instance of Module.
13 14 15 16 17 18 19 20 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 13 def initialize(source = nil, methods = []) @name = "Groups::#{source.name.camelize}" @methods = methods @namespace = source.xmlns_prefix&.camelize yield self if block_given? end |
Instance Attribute Details
#includes ⇒ Object
Returns the value of attribute includes.
11 12 13 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 11 def includes @includes end |
#inherit_from ⇒ Object
Returns the value of attribute inherit_from.
11 12 13 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 11 def inherit_from @inherit_from end |
#methods ⇒ Object
Returns the value of attribute methods.
11 12 13 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 11 def methods @methods end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 11 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 11 def namespace @namespace end |
Instance Method Details
#name_with_prefix ⇒ Object
26 27 28 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 26 def name_with_prefix [namespace, name].compact.map(&:camelize).join('::') end |
#schema(_) ⇒ Object
22 23 24 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 22 def schema(_) STACK end |
#to_builder_s ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 60 def to_builder_s string = ModuleTemplate.new(name.demodulize) do |template| template.namespaces = ['Groups'].compact meth = StringIO.new meth.puts " def builder" meth.puts " root = Ox::Element.new(name)" meth.puts " root = add_attributes_and_namespaces(root)" meth.puts meth.puts methods.map { |method| indent(indent(method.to_builder.lines)).join }.join("\n") meth.puts meth.puts " root" meth.puts " end" template.methods = [meth.string] end.to_s wrapped = string wrapped = wrap_in_namespace(wrapped, namespace) if namespace wrapped end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb', line 30 def to_s string = ModuleTemplate.new(name.demodulize) do |template| template.namespaces = ['Groups'].compact methods.each { |method| template.methods << indent(method.to_s.lines).join } meth = StringIO.new meth.puts " def to_h" meth.puts " hash = {}" meth.puts " hash[:attributes] = attributes" meth.puts methods.each do |method| method.to_h_method.lines.each do |line| meth.puts " #{line}" end end meth.puts meth.puts " hash" meth.puts " end" template.methods << meth.string end.to_s wrapped = string wrapped = wrap_in_namespace(wrapped, namespace) if namespace wrapped end |