Module: Enterprisifier::Marshalling::SchemaComposition::ClassMethods
- Defined in:
- lib/enterprisifier/marshalling/schema_composition.rb
Overview
InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
- #base_name ⇒ Object
- #build(*args, &block) ⇒ Object
- #build_with_parent(parent, *args, &block) ⇒ Object
- #composed_of(*schema_elements) ⇒ Object
- #is_referable? ⇒ Boolean
- #macros(*args) ⇒ Object
- #namespace(ns_settings = nil) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 80 def self.extended(base) base.class_eval <<-EOM attr_accessor :parent class_inheritable_accessor :instance class_inheritable_array :composition write_inheritable_array :composition, [] class << self private :new delegate :reify, :to => :instance end def self.#{base.base_name.to_s.underscore}(*args, &block) self.instance = build(*args, &block) end EOM end |
Instance Method Details
#base_name ⇒ Object
119 120 121 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 119 def base_name name.demodulize.to_sym end |
#build(*args, &block) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 102 def build(*args, &block) new(*args).tap do |i| i.evaluate(block) i.reify_self if i.respond_to?(:reify_self, true) end end |
#build_with_parent(parent, *args, &block) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 109 def build_with_parent(parent, *args, &block) new(*args) do |i| i.parent = parent i end.tap do |i| i.evaluate(block) i.reify_self if i.respond_to?(:reify_self, true) end end |
#composed_of(*schema_elements) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 147 def composed_of(*schema_elements) write_inheritable_array :composition, schema_elements schema_elements.each do |se| class_eval <<-EOM attr_accessor #{se.to_s.underscore.pluralize.inspect} def #{se.to_s.underscore}(*args, &block) builder = ::Enterprisifier::Marshalling::SchemaComposition.schema_elements[#{se.inspect}] builder.build_with_parent(self, *args, &block).tap do |def_i| (self.#{se.to_s.underscore.pluralize} ||= []) << def_i definition_changed(#{se.to_s.underscore.to_sym.inspect}, def_i) if respond_to?(:definition_changed, true) end end class << self delegate #{se.to_s.underscore.inspect}, :to => :instance end EOM end end |
#is_referable? ⇒ Boolean
98 99 100 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 98 def is_referable? false end |
#macros(*args) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 131 def macros(*args) = args. args.each do |m| class_eval <<-EOM def #{m}(val = nil) return @#{m} unless val #{if [:allow_multiple] "(@#{m.to_s.pluralize} ||= []) << val" else "@#{m.to_s.pluralize} = val" end} end EOM end end |
#namespace(ns_settings = nil) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/enterprisifier/marshalling/schema_composition.rb', line 123 def namespace(ns_settings = nil) if ns_settings @namespace = Enterprisifier::Marshalling::Namespace.new(*(ns_settings.to_a.first)) else @namespace end end |