Class: ActiveCollection::Scope::ScopeBuilder
- Inherits:
-
Array
- Object
- Array
- ActiveCollection::Scope::ScopeBuilder
- Defined in:
- lib/active_collection/scope.rb,
lib/active_collection/new_scope.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build(kind, *methods, &block) ⇒ Object
75 76 77 78 79 |
# File 'lib/active_collection/scope.rb', line 75 def self.build(kind, *methods, &block) methods, = (*methods, &block) methods.map! { |method| ActiveSupport::Callbacks::Callback.new(kind, method, ) } new(methods) end |
Instance Method Details
#join ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/active_collection/new_scope.rb', line 89 def join hash = {} each do |scope| next if scope.blank? (scope.keys + hash.keys).uniq.each do |key| merge = hash[key] && params[key] # merge if both scopes have the same key if key == :conditions && merge hash[key] = if params[key].is_a?(Hash) && hash[key].is_a?(Hash) merge_conditions(hash[key].deep_merge(params[key])) else merge_conditions(params[key], hash[key]) end elsif key == :include && merge hash[key] = merge_includes(hash[key], params[key]).uniq elsif key == :joins && merge hash[key] = merge_joins(params[key], hash[key]) else hash[key] = hash[key] || params[key] end end end hash end |
#to_options(object) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/active_collection/scope.rb', line 81 def (object) inject({}) do |h, callback| res = callback.call(object) res ? h.merge(res) : h end end |