Module: Model::DSL

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

Overview

Extensions to Model::DSL

Instance Method Summary collapse

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



7
8
9
10
# File 'lib/model/dsl.rb', line 7

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



16
17
18
# File 'lib/model/dsl.rb', line 16

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



22
23
24
# File 'lib/model/dsl.rb', line 22

def attr_writer(name)
    define_attribute_writer(name)
end