Skip to content

Commit

Permalink
adding ability to designate a nested attribute as "singular", so it will
Browse files Browse the repository at this point in the history
be nil instead of an array when missing
  • Loading branch information
daws committed Jan 18, 2016
1 parent 2aecf76 commit 5ef7679
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/simple_sdk_builder/resource.rb
Expand Up @@ -103,13 +103,14 @@ def simple_sdk_attribute(*attrs)

def simple_sdk_nested_attribute(attr, options = {})
options = {
:nested => true
nested: true,
singular: false
}.merge(options)
attr = attr.to_s
simple_sdk_attributes.push(attr)
simple_sdk_attributes.push("#{attr}_attributes") # for ActiveRecord nested attributes
define_method attr do
@attributes[attr] ||= []
@attributes[attr] ||= options[:singular] ? nil : []
end
alias_method :"#{attr}_attributes", :"#{attr}" # for ActiveRecord nested attributes
define_method "#{attr}=" do |value|
Expand Down

0 comments on commit 5ef7679

Please sign in to comment.