Class: ActiveRecord::AttributeSet::Builder

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types, always_initialized = nil) ⇒ Builder

Returns a new instance of Builder.


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

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

Instance Attribute Details

#always_initializedObject (readonly)

Returns the value of attribute always_initialized


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

def always_initialized
  @always_initialized
end

#typesObject (readonly)

Returns the value of attribute types


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

def types
  @types
end

Instance Method Details

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


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

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)
  AttributeSet.new(attributes)
end