Module: Gorillib::FancyBuilder::ClassMethods

Includes:
Builder::ClassMethods
Defined in:
lib/gorillib/builder.rb

Instance Method Summary collapse

Methods included from Builder::ClassMethods

#collection, #magic, #member

Methods included from Model::ClassMethods

#assemble_positionals, #attrs_hash_from_args, #collection, #field, #field_names, #fields, #from_tuple, #has_field?, #inspect, #inspect_compact, #native?, #positionals, #receive, #typename

Instance Method Details

#belongs_to(field_name, type, options = {}) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/gorillib/builder.rb', line 168

def belongs_to(field_name, type, options={})
  field = member(field_name, type)
  define_meta_module_method "#{field.name}_name" do
    val = getset_member(field) or return nil
    val.name
  end
  field
end

#collects(type, clxn_name) ⇒ Object



182
183
184
185
186
187
# File 'lib/gorillib/builder.rb', line 182

def collects(type, clxn_name)
  type_handle = type.handle
  define_meta_module_method type_handle do |item_name, attrs={}, options={}, &block|
    send(clxn_name, item_name, attrs, options.merge(:factory => type), &block)
  end
end

#option(field_name, options = {}) ⇒ Object



177
178
179
180
# File 'lib/gorillib/builder.rb', line 177

def option(field_name, options={})
  type = options.delete(:type){ Whatever }
  magic(field_name, type)
end