Class: InstantApi::Model::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/instant_api/model/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, klass, root = false) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
10
# File 'lib/instant_api/model/builder.rb', line 6

def initialize(params, klass, root = false)
  @params = params
  @klass = klass
  @root = root
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/instant_api/model/builder.rb', line 4

def klass
  @klass
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/instant_api/model/builder.rb', line 4

def params
  @params
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/instant_api/model/builder.rb', line 4

def root
  @root
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/instant_api/model/builder.rb', line 12

def build
  record = nil
  klass.transaction do
    record = klass.create(params_primitives).tap do |object|
      create_nested_records(object)
    end

    raise ActiveRecord::Rollback if rollback?(record)
  end

  record
end