sakuramochi 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
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
|
22
|
-
|
23
|
-
|
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
|
data/lib/sakuramochi/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.
|
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:
|
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:
|
147
|
+
hash: -1276016523191122260
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project: sakuramochi
|
150
150
|
rubygems_version: 1.8.21
|