module EfoNelfo::HasMany::ClassMethods
Public Instance Methods
association(post_type)
click to toggle source
# File lib/efo_nelfo/has_many.rb, line 62 def association(post_type) type = post_type.is_a?(EfoNelfo::PostType) ? post_type.post_type : post_type.to_s.upcase @associations[type] end
associations()
click to toggle source
# File lib/efo_nelfo/has_many.rb, line 58 def associations @associations end
has_many(name, options)
click to toggle source
# File lib/efo_nelfo/has_many.rb, line 41 def has_many(name, options) post_type = options[:post_type] @associations ||= {} @associations[post_type] = name define_method name do instance_variable_get("@#{name}") || instance_variable_set("@#{name}", EfoNelfo::Collection.new(self, post_type)) end define_method "#{name}=" do |values| instance_variable_set "@#{name}", EfoNelfo::Collection.new(self, post_type) values.each { |item| instance_variable_get("@#{name}") << item } if values end end