Class: GroupedScope::Arish::Associations::Builder::GroupedAssociation
- Inherits:
-
Object
- Object
- GroupedScope::Arish::Associations::Builder::GroupedAssociation
- Defined in:
- lib/grouped_scope/arish/associations/builder/grouped_association.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#grouped_name ⇒ Object
readonly
Returns the value of attribute grouped_name.
-
#grouped_options ⇒ Object
readonly
Returns the value of attribute grouped_options.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#ungrouped_name ⇒ Object
readonly
Returns the value of attribute ungrouped_name.
-
#ungrouped_reflection ⇒ Object
readonly
Returns the value of attribute ungrouped_reflection.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(model, ungrouped_name) ⇒ GroupedAssociation
constructor
A new instance of GroupedAssociation.
Constructor Details
#initialize(model, ungrouped_name) ⇒ GroupedAssociation
Returns a new instance of GroupedAssociation.
13 14 15 16 17 18 19 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 13 def initialize(model, ungrouped_name) @model = model @ungrouped_name = ungrouped_name @ungrouped_reflection = find_ungrouped_reflection @grouped_name = :"grouped_scope_#{ungrouped_name}" @grouped_options = end |
Instance Attribute Details
#grouped_name ⇒ Object (readonly)
Returns the value of attribute grouped_name.
7 8 9 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 7 def grouped_name @grouped_name end |
#grouped_options ⇒ Object (readonly)
Returns the value of attribute grouped_options.
7 8 9 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 7 def @grouped_options end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 7 def model @model end |
#ungrouped_name ⇒ Object (readonly)
Returns the value of attribute ungrouped_name.
7 8 9 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 7 def ungrouped_name @ungrouped_name end |
#ungrouped_reflection ⇒ Object (readonly)
Returns the value of attribute ungrouped_reflection.
7 8 9 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 7 def ungrouped_reflection @ungrouped_reflection end |
Class Method Details
.build(model, *association_names) ⇒ Object
9 10 11 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 9 def self.build(model, *association_names) association_names.each { |ungrouped_name| new(model, ungrouped_name).build } end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/grouped_scope/arish/associations/builder/grouped_association.rb', line 21 def build model.send(ungrouped_reflection.macro, grouped_name, ).tap do |grouped_reflection| grouped_reflection.grouped_scope = true model.grouped_reflections = model.grouped_reflections.merge(ungrouped_name => grouped_reflection) define_grouped_scope_reader end end |