Class: ActiveHash::Base::WhereChain
- Inherits:
-
Object
- Object
- ActiveHash::Base::WhereChain
- Defined in:
- lib/active_hash/base.rb
Instance Method Summary collapse
-
#initialize(scope) ⇒ WhereChain
constructor
A new instance of WhereChain.
- #not(options) ⇒ Object
Constructor Details
#initialize(scope) ⇒ WhereChain
Returns a new instance of WhereChain.
20 21 22 23 |
# File 'lib/active_hash/base.rb', line 20 def initialize(scope) @scope = scope @records = @scope.all end |
Instance Method Details
#not(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_hash/base.rb', line 25 def not() return @records if .blank? # use index if searching by id if .key?(:id) || .key?("id") ids = @scope.pluck(:id) - Array.wrap(.delete(:id) || .delete("id")) candidates = ids.map { |id| @scope.find_by_id(id) }.compact end return candidates if .blank? (candidates || @records || []).reject do |record| (record, ) end end |