Class: Sakuramochi::Configuration
- Inherits:
-
Object
- Object
- Sakuramochi::Configuration
- Defined in:
- lib/sakuramochi/configuration.rb
Instance Attribute Summary collapse
-
#predicates ⇒ Object
Returns the value of attribute predicates.
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #restore ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 |
# File 'lib/sakuramochi/configuration.rb', line 7 def initialize @predicates = {} restore end |
Instance Attribute Details
#predicates ⇒ Object
Returns the value of attribute predicates.
5 6 7 |
# File 'lib/sakuramochi/configuration.rb', line 5 def predicates @predicates end |
Instance Method Details
#add(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sakuramochi/configuration.rb', line 12 def add(*args) = args. .reverse_merge!(:grouping => true) suffixes = [nil] suffixes += ['any', 'all'] if [:grouping] args.flatten.each do |name| name = name.to_s suffixes.each do |suffix| predicate_name = [name, suffix].compact.join('_') @predicates[predicate_name] = Predicate.new(.merge({ :name => predicate_name, :arel_predicate => [[:arel_predicate], suffix].compact.join('_') })) end end end |
#clear ⇒ Object
31 32 33 |
# File 'lib/sakuramochi/configuration.rb', line 31 def clear @predicates.clear end |
#restore ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sakuramochi/configuration.rb', line 35 def restore clear names = { :contains => [:contains], :starts_with => [:starts_with, :start_with], :ends_with => [:ends_with, :end_with], :in => [:in], :eq => [:eq, :equal, :equals], :gt => [:gt], :gte => [:gte, :gteq], :lt => [:lt], :lte => [:lte, :lteq], } negative = proc { |p| "not_#{p}" } add names[:contains], :arel_predicate => :matches, :converter => proc { |v| "%#{v}%" } add names[:contains].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "%#{v}%" } add names[:starts_with], :arel_predicate => :matches, :converter => proc { |v| "#{v}%" } add names[:starts_with].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "#{v}%" } add names[:ends_with], :arel_predicate => :matches, :converter => proc { |v| "%#{v}" } add names[:ends_with].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "%#{v}" } add names[:in], :arel_predicate => :in add names[:in].map(&negative), :arel_predicate => :not_in add names[:eq], :arel_predicate => :eq add names[:eq].map(&negative), :ne, :arel_predicate => :not_eq add names[:gt], :arel_predicate => :gt add names[:gte], :arel_predicate => :gteq add names[:lt], :arel_predicate => :lt add names[:lte], :arel_predicate => :lteq end |