module Syrup::Relations::ClassMethods
Public Instance Methods
accepts_nested_attributes_for(*relations)
click to toggle source
# File lib/syrup/relations.rb, line 11 def accepts_nested_attributes_for(*relations) relations.each do |relation| build_attributes_setter relation add_relation(relation) end end
add_relation(klass)
click to toggle source
# File lib/syrup/relations.rb, line 36 def add_relation(klass) relations << klass unless relations.include?(klass) end
build_attributes_setter(relation)
click to toggle source
build_attributes_setter
'address'
def address_attributes=(attributes)
address.attributes=attributes
end
# File lib/syrup/relations.rb, line 24 def build_attributes_setter(relation) module_eval <<-EOH def #{relation}_attributes=(attributes) #{relation}.attributes=attributes end EOH end
has_one(klass)
click to toggle source
# File lib/syrup/relations.rb, line 40 def has_one(klass) add_relation(klass) attr_accessor klass end
relations()
click to toggle source
# File lib/syrup/relations.rb, line 32 def relations @relations ||= [] end