Sha256: 486cef514717fca895c720c62d0a51178106d0f7dc7d6b75b03bd301b0f8494e
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
module SymbolOperatorMethods OPERATORS = { :eql => '==', :not_eql => '!=', :gt => '>', :gte => '>=', :lt => '<', :lte => '<=', :matches => '==', :does_not_match => '!=', :contains => '=~', :does_not_contain => '!~', :substring => '=@', :not_substring => '!@', :desc => '-', :descending => '-' } SLUGS = OPERATORS.keys.freeze def to_google_analytics t = Garb.to_google_analytics @field || @target o = OPERATORS[@operator] [:desc, :descending].include?(@operator) ? "#{o}#{t}" : "#{t}#{o}" end end class SymbolOperator include SymbolOperatorMethods def initialize(field, operator) @field, @operator = field, operator end unless method_defined? :initialize end symbol_slugs = if Object.const_defined?('DataMapper') # make sure the class is defined require 'dm-core/core_ext/symbol' # add to_google_analytics to DM's Opeartor class DataMapper::Query::Operator include SymbolOperatorMethods end SymbolOperatorMethods::SLUGS - DataMapper::Query::Conditions::Comparison.slugs else SymbolOperatorMethods::SLUGS end # define the remaining symbol operators symbol_slugs.each do |operator| Symbol.class_eval <<-RUBY def #{operator} SymbolOperator.new self, :#{operator} end unless method_defined? :#{operator} RUBY end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
garb-0.9.8 | lib/garb/core_ext/symbol.rb |
garb-0.9.7 | lib/garb/core_ext/symbol.rb |