module DCA::Models::Binder::ClassMethods
Public Instance Methods
associations(complex = false)
click to toggle source
# File lib/dca/models/binder.rb, line 25 def associations complex = false @associations ||= {} return associations.select { |field, options| !COMPLEX_TYPE.include?(options[:type]) } if complex @associations end
binder(name = :nokogiri)
click to toggle source
# File lib/dca/models/binder.rb, line 9 def binder name = :nokogiri @binder ||= "DCA::Models::#{name.to_s.camelize}Binder".constantize end
has_many(field, *args)
click to toggle source
# File lib/dca/models/binder.rb, line 19 def has_many field, *args options = args.extract_options! type = args.first add_association field, :many, type, options end
has_one(field, *args)
click to toggle source
# File lib/dca/models/binder.rb, line 13 def has_one field, *args options = args.extract_options! type = args.first add_association field, :one, type, options end
inherited(child)
click to toggle source
# File lib/dca/models/binder.rb, line 33 def inherited(child) associations.each { |field, options| child.associations[field] = options} end
Private Instance Methods
add_association(field, association, type, options = {})
click to toggle source
# File lib/dca/models/binder.rb, line 39 def add_association field, association, type, options = {} associations[field] = { :association => association, :field => field, :type => type, :options => options } instance_eval do attr_accessor field.to_sym unless instance_variable_defined? "@#{field}" end end