Skip to content

Releases: onthebeach/structural

Allow has_one association to support default option

20 Feb 10:54
Compare
Choose a tag to compare

Currently has_one always raises an error if the key isn't passed
in as data. This change allows a default to be specified that will
be used when initializing the associated structural class.

One use-case for this is to allow the creation of naive structural
classes with nested associations.

class CustomerDetails
  field :account_name, default: nil

  has_one :credentials, default: {}, type: Credentials
  has_one :billing_address, default: {}, type: BillingAddress

  def name
    account_name || credentials.name || billing_address.name
  end
end

In the above snippet, we know that there are three ways to pass the
customer's name: as top-level account_name, as name nested in
credentials or as name nested in billing_address.

Having a default allows you to specify a single access point that
attempts to access the data from the various sources.

Version 0.1.0 (November 7th 2016)

07 Nov 16:56
Compare
Choose a tag to compare

Reduce the number of objects allocations #4