Sha256: b04863ba9cb8f6a31c1cd9c8707575b1e6e4a20c02f025a09ffc7786b3068e24

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'active_set/version'

require 'active_set/processors/filter_processor'
require 'active_set/processors/sort_processor'
require 'active_set/processors/paginate_processor'
require 'active_set/processors/transform_processor'

class ActiveSet
  include Enumerable

  attr_reader :set

  def initialize(set)
    @set = set
  end

  def each(&block)
    @set.each(&block)
  end

  def ==(other)
    return @set == other unless other.is_a?(ActiveSet)
    @set == other.set
  end

  def method_missing(method_name, *args, &block)
    @set.send(method_name, *args, &block) || super
  end

  def respond_to_missing?(method_name, include_private = false)
    @set.respond_to?(method_name) || super
  end

  def filter(instructions)
    filterer = FilterProcessor.new(@set, instructions)
    self.class.new(filterer.process)
  end

  def sort(instructions)
    sorter = SortProcessor.new(@set, instructions)
    self.class.new(sorter.process)
  end

  def paginate(instructions)
    paginater = PaginateProcessor.new(@set, instructions)
    self.class.new(paginater.process)
  end

  def transform(instructions)
    transformer = TransformProcessor.new(@set, instructions)
    transformer.process
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeset-0.5.1 lib/active_set.rb