Class: Filterameter::Helpers::JoinsValuesBuilder
- Inherits:
-
Object
- Object
- Filterameter::Helpers::JoinsValuesBuilder
- Defined in:
- lib/filterameter/helpers/joins_values_builder.rb
Overview
# Joins Values Builder
Class JoinsValuesBuilder evaluates an array of names to return either the single entry when there is only one element in the array or a nested hash when there is more than one element. This is the argument that is passed into the ActiveRecord query method ‘joins`.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(association_names) ⇒ JoinsValuesBuilder
constructor
A new instance of JoinsValuesBuilder.
- #to_h ⇒ Object
Constructor Details
#initialize(association_names) ⇒ JoinsValuesBuilder
Returns a new instance of JoinsValuesBuilder.
17 18 19 |
# File 'lib/filterameter/helpers/joins_values_builder.rb', line 17 def initialize(association_names) @association_names = association_names end |
Class Method Details
.build(association_names) ⇒ Object
11 12 13 14 15 |
# File 'lib/filterameter/helpers/joins_values_builder.rb', line 11 def self.build(association_names) return association_names.first if association_names.size == 1 new(association_names).to_h end |
Instance Method Details
#to_h ⇒ Object
21 22 23 24 25 |
# File 'lib/filterameter/helpers/joins_values_builder.rb', line 21 def to_h {}.tap do |nested_hash| @association_names.reduce(nested_hash) { |memo, name| memo.store(name, {}) } end end |