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

Instance Method Summary collapse

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.

Raises:

  • (NotImplementedError)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ghaki/meta/builder.rb', line 15

def make_meta_builder token, *args
  klass = self.class.meta_builders[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 setup_meta_builders *args
  self.class.meta_builders.each_key do |token|
    make_meta_builder token, *args
  end
end