Sha256: cfe7960eabcae0554f781892494bb18d7bb0c7eea3edcda92f09c1b805acc16b

Contents?: true

Size: 721 Bytes

Versions: 15

Compression:

Stored size: 721 Bytes

Contents

class ModelSet
  class RawQuery < Query
    attr_reader :records

    def anchor!(query, raw_method = 'find_raw_by_id')
      @records = model_class.send(raw_method, query.ids.to_a)
    end

    def select!(&block)
      records.select!(&block)
    end

    def reject!(&block)
      records.reject!(&block)
    end

    def sort_by!(&block)
      @records = records.sort_by(&block)
    end

    def ids
      if limit
        (records[offset, limit] || []).collect {|r| r['id'].to_i}
      else
        records.collect {|r| r['id'].to_i}
      end
    end
    
    def size
      if limit
        [count - offset, limit].min
      else
        count
      end
    end

    def count
      records.size
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
ninjudd-model_set-0.10.0 lib/model_set/raw_query.rb
ninjudd-model_set-0.10.1 lib/model_set/raw_query.rb
ninjudd-model_set-0.10.2 lib/model_set/raw_query.rb
ninjudd-model_set-0.10.3 lib/model_set/raw_query.rb
ninjudd-model_set-0.10.4 lib/model_set/raw_query.rb
ninjudd-model_set-0.10.5 lib/model_set/raw_query.rb
ninjudd-model_set-0.9.2 lib/model_set/raw_query.rb
model_set-1.1.3 lib/model_set/raw_query.rb
model_set-1.1.2 lib/model_set/raw_query.rb
model_set-1.1.1 lib/model_set/raw_query.rb
model_set-1.1.0 lib/model_set/raw_query.rb
model_set-1.0.0 lib/model_set/raw_query.rb
model_set-0.11.1 lib/model_set/raw_query.rb
model_set-0.11.0 lib/model_set/raw_query.rb
model_set-0.10.6 lib/model_set/raw_query.rb