Class: ArOuterJoins::Join
- Inherits:
-
Object
- Object
- ArOuterJoins::Join
- Defined in:
- lib/ar_outer_joins/join.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #apply(*args) ⇒ Object
- #generate(*args) ⇒ Object
-
#initialize(klass) ⇒ Join
constructor
A new instance of Join.
Constructor Details
#initialize(klass) ⇒ Join
Returns a new instance of Join.
5 6 7 |
# File 'lib/ar_outer_joins/join.rb', line 5 def initialize(klass) @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/ar_outer_joins/join.rb', line 3 def klass @klass end |
Instance Method Details
#apply(*args) ⇒ Object
22 23 24 |
# File 'lib/ar_outer_joins/join.rb', line 22 def apply(*args) klass.joins(generate(*args)) end |
#generate(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ar_outer_joins/join.rb', line 9 def generate(*args) args.flatten.compact.map do |arg| if arg.is_a?(Hash) arg.map do |key, value| association = klass.reflect_on_association(key) generate(key) + Join.new(association.klass).generate(value) end else JoinBuilder.new(klass.reflect_on_association(arg)).build end end end |