class ScaffoldParser::Scaffolders::XSD::Parser::Handlers::Module

Attributes

includes[RW]
inherit_from[RW]
methods[RW]
name[RW]
namespace[RW]

Public Class Methods

new(source = nil, methods = []) { |self| ... } click to toggle source
# 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

Public Instance Methods

name_with_prefix() click to toggle source
# File lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb, line 26
def name_with_prefix
  [namespace, name].compact.map(&:camelize).join('::')
end
schema(_) click to toggle source
# File lib/scaffold_parser/scaffolders/xsd/parser/handlers/module.rb, line 22
def schema(_)
  STACK
end
to_builder_s() click to toggle source
# 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() click to toggle source
# 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