sakuramochi 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/sakuramochi.rb CHANGED
@@ -10,43 +10,13 @@ module Sakuramochi
10
10
  autoload :Condition, 'sakuramochi/condition'
11
11
  autoload :Relation, 'sakuramochi/relation'
12
12
 
13
- def self.configure(&block)
14
- yield @config ||= Sakuramochi::Configuration.new
15
- end
16
-
17
13
  def self.config
18
- @config
14
+ @config ||= Sakuramochi::Configuration.new
19
15
  end
20
16
 
21
- configure do |config|
22
- predicates = {
23
- :contains => [:contains],
24
- :starts_with => [:starts_with, :start_with],
25
- :ends_with => [:ends_with, :end_with],
26
- :in => [:in],
27
- :eq => [:eq, :equal, :equals],
28
- :gt => [:gt],
29
- :gte => [:gte, :gteq],
30
- :lt => [:lt],
31
- :lte => [:lte, :lteq],
32
- }
33
- negative = proc { |p| "not_#{p}" }
34
-
35
- config.add predicates[:contains], :arel_predicate => :matches, :converter => proc { |v| "%#{v}%" }
36
- config.add predicates[:contains].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "%#{v}%" }
37
- config.add predicates[:starts_with], :arel_predicate => :matches, :converter => proc { |v| "#{v}%" }
38
- config.add predicates[:starts_with].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "#{v}%" }
39
- config.add predicates[:ends_with], :arel_predicate => :matches, :converter => proc { |v| "%#{v}" }
40
- config.add predicates[:ends_with].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "%#{v}" }
41
- config.add predicates[:in], :arel_predicate => :in
42
- config.add predicates[:in].map(&negative), :arel_predicate => :not_in
43
- config.add predicates[:eq], :arel_predicate => :eq
44
- config.add predicates[:eq].map(&negative), :ne, :arel_predicate => :not_eq
45
- config.add predicates[:gt], :arel_predicate => :gt
46
- config.add predicates[:gte], :arel_predicate => :gteq
47
- config.add predicates[:lt], :arel_predicate => :lt
48
- config.add predicates[:lte], :arel_predicate => :lteq
49
- end
17
+ def self.configure(&block)
18
+ yield config
19
+ end
50
20
 
51
21
  ActiveSupport.on_load(:active_record) do
52
22
  ActiveRecord::Relation.send(:include, Sakuramochi::Relation)
@@ -6,6 +6,7 @@ module Sakuramochi
6
6
 
7
7
  def initialize
8
8
  @predicates = {}
9
+ restore
9
10
  end
10
11
 
11
12
  def add(*args)
@@ -26,5 +27,41 @@ module Sakuramochi
26
27
  end
27
28
  end
28
29
  end
30
+
31
+ def clear
32
+ @predicates.clear
33
+ end
34
+
35
+ def restore
36
+ clear
37
+
38
+ names = {
39
+ :contains => [:contains],
40
+ :starts_with => [:starts_with, :start_with],
41
+ :ends_with => [:ends_with, :end_with],
42
+ :in => [:in],
43
+ :eq => [:eq, :equal, :equals],
44
+ :gt => [:gt],
45
+ :gte => [:gte, :gteq],
46
+ :lt => [:lt],
47
+ :lte => [:lte, :lteq],
48
+ }
49
+ negative = proc { |p| "not_#{p}" }
50
+
51
+ add names[:contains], :arel_predicate => :matches, :converter => proc { |v| "%#{v}%" }
52
+ add names[:contains].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "%#{v}%" }
53
+ add names[:starts_with], :arel_predicate => :matches, :converter => proc { |v| "#{v}%" }
54
+ add names[:starts_with].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "#{v}%" }
55
+ add names[:ends_with], :arel_predicate => :matches, :converter => proc { |v| "%#{v}" }
56
+ add names[:ends_with].map(&negative), :arel_predicate => :does_not_match, :converter => proc { |v| "%#{v}" }
57
+ add names[:in], :arel_predicate => :in
58
+ add names[:in].map(&negative), :arel_predicate => :not_in
59
+ add names[:eq], :arel_predicate => :eq
60
+ add names[:eq].map(&negative), :ne, :arel_predicate => :not_eq
61
+ add names[:gt], :arel_predicate => :gt
62
+ add names[:gte], :arel_predicate => :gteq
63
+ add names[:lt], :arel_predicate => :lt
64
+ add names[:lte], :arel_predicate => :lteq
65
+ end
29
66
  end
30
67
  end
@@ -1,3 +1,3 @@
1
1
  module Sakuramochi
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -5,6 +5,7 @@ describe Sakuramochi::PredicateBuilder do
5
5
  describe 'matches' do
6
6
  before do
7
7
  Sakuramochi.configure do |config|
8
+ config.clear
8
9
  config.add :contains, :arel_predicate => :matches, :converter => proc { |v| "%#{v}%" }
9
10
  end
10
11
  @statuses = Status.where(key => value)
@@ -86,6 +86,7 @@ describe Sakuramochi::Predicate do
86
86
  context 'config.add :test' do
87
87
  before do
88
88
  Sakuramochi.configure do |config|
89
+ config.clear
89
90
  config.add :test
90
91
  end
91
92
  end
data/spec/spec_helper.rb CHANGED
@@ -12,4 +12,7 @@ RSpec.configure do |config|
12
12
  CreateTestTables.up
13
13
  CreateTestTables.seed
14
14
  end
15
+ config.after do
16
+ Sakuramochi.config.restore
17
+ end
15
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakuramochi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 1227588817688317651
138
+ hash: -1276016523191122260
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: 1227588817688317651
147
+ hash: -1276016523191122260
148
148
  requirements: []
149
149
  rubyforge_project: sakuramochi
150
150
  rubygems_version: 1.8.21