Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
21 lines (13 sloc) 714 Bytes

Unknown attributes

Sometimes JSON structure changes and it contains more keys than attributes defined in your StoreModel::Model class. In such cases, "unknown" attributes can be found inside the #unknown_attributes hash:

class Configuration
  include StoreModel::Model

  attribute :color, :string
end

configuration = Configuration.to_type.cast_value(color: "red", archived: true)
configuration.unknown_attributes # => { "archived" => true }

# OR

configurations = Configuration.to_array_type.cast_value( [{ color: "red", archived: true }, [{ color: "blue", archived: false }])
configurations.map { |config| config.unknown_attributes } # => [{ "archived" => true }, { "archived" => false }]
You can’t perform that action at this time.