scope_composer 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/scope_composer/scope.rb +17 -17
- data/lib/scope_composer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzU4YTJkM2I2ZGQzNTkxMjg4N2FmYWJiYmFiM2Q1OGRkNGNjNDJhYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWJhNDJlZDdmNzI2NjhkNGU2ZjFlZGFlNGQ1NmVjNzFjOGUxNTZjOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTA0MWU3ZTA3MTE3OGJkZGVhZjU0MWFhZTMzZjA3MjU2MTEwM2ZkMGRmNWI5
|
10
|
+
MWRiYzBkMTkzMzdhYjgwZTU1YTBiMjBkYzNkZDQwMThlYjVjMmRjNmQyN2Qx
|
11
|
+
MWM3MDI3NWQ4NWU3NDgwOGFkYzUyMjg3ZDYyNmQyMGUyYjIwMGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTAxNWE1ZjAwMDc4NWE5MzcxNzcxMGY1ZTk4NTcyMTk2ZWVmZGMwZWUyNTJm
|
14
|
+
MTBlMGM1MTdkOGM2OTc2MWRmNzg0MjkwYTU4OTQxNDgzNjAyMjgzMTBiMzE0
|
15
|
+
YWY2MTc4OThlNThkYmYyZDBmZTM0NDc3MTRhY2IwOTE1ZTIwYjE=
|
data/lib/scope_composer/scope.rb
CHANGED
@@ -92,14 +92,14 @@ class Scope
|
|
92
92
|
# define method
|
93
93
|
define_method(name) do |*args|
|
94
94
|
# if no value is given, act as a getter and retrieve the value
|
95
|
-
return
|
95
|
+
return read_scope_attribute(key) if args.compact.blank?
|
96
96
|
# otherwise set the value
|
97
97
|
instance_exec(*args, &proc)
|
98
98
|
# and return self for chaining
|
99
99
|
self
|
100
100
|
end
|
101
|
-
define_method("#{name}=") do |
|
102
|
-
self.send( name,
|
101
|
+
define_method("#{name}=") do |*args|
|
102
|
+
self.send( name, *args )
|
103
103
|
end
|
104
104
|
# add to scope list
|
105
105
|
scopes[name] = proc
|
@@ -115,19 +115,15 @@ class Scope
|
|
115
115
|
name = name.to_sym
|
116
116
|
# define method
|
117
117
|
define_method(name) do |*args|
|
118
|
-
#
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# if no value is given, act as a getter
|
123
|
-
return scope_attributes[name] if values.nil?
|
124
|
-
# otherwise set the value
|
125
|
-
scope_attributes[name] = values
|
118
|
+
# without args return the value
|
119
|
+
return read_scope_attribute(name) if args.compact.blank?
|
120
|
+
# given args, set value
|
121
|
+
self.send("#{name}=", args)
|
126
122
|
# and return self for chaining
|
127
123
|
return self
|
128
124
|
end
|
129
125
|
define_method("#{name}=") do |*args|
|
130
|
-
|
126
|
+
write_scope_attribute(name, *args)
|
131
127
|
end
|
132
128
|
# add to scoping list
|
133
129
|
scopes[name] = nil
|
@@ -137,6 +133,14 @@ class Scope
|
|
137
133
|
|
138
134
|
delegate :to_param, to: :attributes
|
139
135
|
|
136
|
+
def read_scope_attribute(key)
|
137
|
+
scope_attributes[key]
|
138
|
+
end
|
139
|
+
|
140
|
+
def write_scope_attribute(key, values)
|
141
|
+
scope_attributes[key] = (values.count == 1) ? values.first : values
|
142
|
+
end
|
143
|
+
|
140
144
|
def assign_attributes(*attrs)
|
141
145
|
attrs = attrs.extract_options!
|
142
146
|
attrs.each do |key, value|
|
@@ -144,17 +148,13 @@ class Scope
|
|
144
148
|
end
|
145
149
|
end
|
146
150
|
|
147
|
-
def attributes
|
148
|
-
self.class.scopes.keys.inject({}){|m,k| m.merge( k => attributes[k] ) }
|
149
|
-
end
|
150
|
-
|
151
151
|
def where(*args)
|
152
152
|
attrs = args.extract_options!
|
153
153
|
attrs.symbolize_keys!
|
154
154
|
self.attributes = attrs
|
155
155
|
self
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
def attributes
|
159
159
|
@attributes ||= {}
|
160
160
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scope_composer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hilscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|