Sha256: 3011f399dc83cb770a603f0fbe19dfa6fd5ad667cdcaeea5d3739821182c5540

Contents?: true

Size: 847 Bytes

Versions: 18

Compression:

Stored size: 847 Bytes

Contents

module Graphiti
  class FilterOperators
    class Catchall
      attr_reader :procs

      def initialize(resource, type_name, opts)
        @procs = {}
        defaults = resource.adapter.default_operators[type_name] || [:eq]
        if opts[:only]
          defaults = defaults.select { |op| Array(opts[:only]).include?(op) }
        end
        if opts[:except]
          defaults = defaults.reject { |op| Array(opts[:except]).include?(op) }
        end
        defaults.each do |op|
          @procs[op] = nil
        end
      end

      def method_missing(name, *args, &blk)
        @procs[name] = blk
      end

      def to_hash
        @procs
      end
    end

    def self.build(resource, type_name, opts = {}, &blk)
      c = Catchall.new(resource, type_name, opts)
      c.instance_eval(&blk) if blk
      c.to_hash
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
graphiti-1.0.rc.21 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.19 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.18 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.17 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.16 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.15 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.14 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.12 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.11 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.10 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.9 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.8 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.7 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.6 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.5 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.4 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.3 lib/graphiti/filter_operators.rb
graphiti-1.0.rc.2 lib/graphiti/filter_operators.rb