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) ⇒ Builder

Returns a new instance of Builder.



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

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.



4
5
6
# File 'lib/active_record/attribute_set/builder.rb', line 4

def always_initialized
  @always_initialized
end

#typesObject (readonly)

Returns the value of attribute types.



4
5
6
# File 'lib/active_record/attribute_set/builder.rb', line 4

def types
  @types
end

Instance Method Details

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



11
12
13
14
15
16
17
18
# File 'lib/active_record/attribute_set/builder.rb', line 11

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