Class: ActiveRecord::AttributeSet::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/attribute_set/builder.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types, always_initialized = nil, &default) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
# File 'lib/active_record/attribute_set/builder.rb', line 8

def initialize(types, always_initialized = nil, &default)
  @types = types
  @always_initialized = always_initialized
  @default = default
end

Instance Attribute Details

#always_initializedObject (readonly)

Returns the value of attribute always_initialized.



6
7
8
# File 'lib/active_record/attribute_set/builder.rb', line 6

def always_initialized
  @always_initialized
end

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/active_record/attribute_set/builder.rb', line 6

def default
  @default
end

#typesObject (readonly)

Returns the value of attribute types.



6
7
8
# File 'lib/active_record/attribute_set/builder.rb', line 6

def types
  @types
end

Instance Method Details

#build_from_database(values = {}, additional_types = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/active_record/attribute_set/builder.rb', line 14

def build_from_database(values = {}, additional_types = {})
  if always_initialized && !values.key?(always_initialized)
    values[always_initialized] = nil
  end

  attributes = LazyAttributeHash.new(types, values, additional_types, &default)
  AttributeSet.new(attributes)
end