Sha256: 8aff84d6a7abdb6f088c28a90a948049d998a6505023a4044320502c7a646448

Contents?: true

Size: 705 Bytes

Versions: 19

Compression:

Stored size: 705 Bytes

Contents

module AttrJson
  module NestedAttributes
    # Implementation of `build_` methods, called by the `build_` methods
    # {NestedAttributes} adds.
    class Builder
      attr_reader :model, :attr_name, :attr_def

      def initialize(model, attr_name)
        @model, @attr_name = model, attr_name,
        @attr_def = model.class.attr_json_registry[attr_name]
      end

      def build(params = {})
        if attr_def.array_type?
          model.send("#{attr_name}=", (model.send(attr_name) || []) + [params])
          return model.send("#{attr_name}").last
        else
          model.send("#{attr_name}=", params)
          return model.send("#{attr_name}")
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
attr_json-2.2.0 lib/attr_json/nested_attributes/builder.rb
attr_json-2.1.0 lib/attr_json/nested_attributes/builder.rb
attr_json-2.0.1 lib/attr_json/nested_attributes/builder.rb
attr_json-2.0.0 lib/attr_json/nested_attributes/builder.rb
attr_json-2.0.0.rc1 lib/attr_json/nested_attributes/builder.rb
attr_json-1.5.0 lib/attr_json/nested_attributes/builder.rb
attr_json-1.4.1 lib/attr_json/nested_attributes/builder.rb
attr_json-1.4.0 lib/attr_json/nested_attributes/builder.rb
attr_json-1.3.0 lib/attr_json/nested_attributes/builder.rb
attr_json-1.2.0 lib/attr_json/nested_attributes/builder.rb
attr_json-1.1.0 lib/attr_json/nested_attributes/builder.rb
attr_json-1.0.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.7.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.6.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.5.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.4.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.3.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.2.0 lib/attr_json/nested_attributes/builder.rb
attr_json-0.1.0 lib/attr_json/nested_attributes/builder.rb