Module: Model::DSL

Included in:
Engineering::Builder::Model
Defined in:
lib/model/dsl.rb

Overview

Extensions to Model::DSL

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If the missing method happens to be the same as a known subclass of

{Model}, then pass the call to the push method.


30
31
32
33
34
35
36
37
# File 'lib/model/dsl.rb', line 30

def method_missing(method, *args, &block)
    klass = Object.const_get(method)
    if klass <= Model
	push klass, *args, &block
    end
rescue
    super
end

Instance Method Details

#attr_accessor(name, value = nil, &block) ⇒ Object Also known as: attribute

Define a new read-write Model attribute. An optional default value can be supplied as either an argument, or as a block. The block will be evaluated the first time the attribute is accessed.

Parameters:

  • name (String, Symbol)

    The new attribute’s name

  • value (defaults to: nil)

    A default value for the new attribute



9
10
11
12
# File 'lib/model/dsl.rb', line 9

def attr_accessor(name, value=nil, &block)
    define_attribute_reader name, value, &block
    define_attribute_writer name
end

#attr_reader(name, value = nil, &block) ⇒ Object

Define a new read-only Model attribute. An optional default value can be supplied as either an argument, or as a block. The block will be evaluated the first time the attribute is accessed.

Parameters:

  • name (String, Symbol)

    The new attribute’s name

  • value (defaults to: nil)

    A default value for the new attribute



18
19
20
# File 'lib/model/dsl.rb', line 18

def attr_reader(name, value=nil, &block)
    define_attribute_reader(name, value, &block)
end

#attr_writer(name) ⇒ Object

Define a new write-only Model attribute

Parameters:

  • name (String, Symbol)

    The new attribute’s name



24
25
26
# File 'lib/model/dsl.rb', line 24

def attr_writer(name)
    define_attribute_writer(name)
end