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.
28 29 30 31 |
# File 'lib/active_hash/base.rb', line 28 def initialize(scope) @scope = scope @records = @scope.all end |
Instance Method Details
#not(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_hash/base.rb', line 33 def not() return @scope 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 filtered_records = (candidates || @records || []).reject do |record| .present? && (record, ) end ActiveHash::Relation.new(@scope.klass, filtered_records, {}) end |