Module: Ghaki::Meta::Builder
- Defined in:
- lib/ghaki/meta/builder.rb
Overview
Allow meta classes to be specified for later creation.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(klass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#make_meta_builder(token, *args) ⇒ Object
Make meta object using builder.
-
#setup_meta_builders(*args) ⇒ Object
Generate meta objects using builders.
Class Method Details
.included(klass) ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/ghaki/meta/builder.rb', line 58 def self.included klass #:nodoc: klass.extend ClassMethods end |
Instance Method Details
#make_meta_builder(token, *args) ⇒ Object
Make meta object using builder.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ghaki/meta/builder.rb', line 15 def token, *args klass = self.class.[token] raise NotImplementedError, "Meta Builder Not Set: #{token}" if klass.nil? obj = if klass.respond_to?(:new) klass.new( *args ) elsif klass.respond_to?(:create) klass.create( *args ) else raise NotImplementedError, "Unknown Builder For Class: #{klass}" end self.send( (token.to_s + '=').to_sym, obj ) end |
#setup_meta_builders(*args) ⇒ Object
Generate meta objects using builders.
8 9 10 11 12 |
# File 'lib/ghaki/meta/builder.rb', line 8 def *args self.class..each_key do |token| token, *args end end |