Class: Friendly::Associations::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly/associations/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, association_klass = Association) ⇒ Set

Returns a new instance of Set.



6
7
8
9
10
# File 'lib/friendly/associations/set.rb', line 6

def initialize(klass, association_klass = Association)
  @klass             = klass
  @association_klass = association_klass
  @associations      = {}
end

Instance Attribute Details

#association_klassObject (readonly)

Returns the value of attribute association_klass.



4
5
6
# File 'lib/friendly/associations/set.rb', line 4

def association_klass
  @association_klass
end

#associationsObject (readonly)

Returns the value of attribute associations.



4
5
6
# File 'lib/friendly/associations/set.rb', line 4

def associations
  @associations
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/friendly/associations/set.rb', line 4

def klass
  @klass
end

Instance Method Details

#add(name, options = {}) ⇒ Object



12
13
14
15
# File 'lib/friendly/associations/set.rb', line 12

def add(name, options = {})
  associations[name] = association_klass.new(klass, name, options)
  add_association_accessor(name)
end

#get(name) ⇒ Object



21
22
23
# File 'lib/friendly/associations/set.rb', line 21

def get(name)
  associations[name]
end

#get_scope(name, document) ⇒ Object



17
18
19
# File 'lib/friendly/associations/set.rb', line 17

def get_scope(name, document)
  get(name).scope(document)
end