Module: DCA::Models::Binder::ClassMethods

Defined in:
lib/dca/models/binder.rb

Instance Method Summary collapse

Instance Method Details

#associations(complex = false) ⇒ Object



25
26
27
28
29
30
31
# 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) ⇒ Object



9
10
11
# 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) ⇒ Object



19
20
21
22
23
# 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) ⇒ Object



13
14
15
16
17
# 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) ⇒ Object



33
34
35
# File 'lib/dca/models/binder.rb', line 33

def inherited(child)
  associations.each { |field, options| child.associations[field] = options}
end