parsecom 0.5.9 → 0.5.10
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/parse/date.rb +21 -3
- data/lib/parse/object.rb +6 -2
- data/lib/parse/query.rb +11 -0
- data/lib/parse/version.rb +1 -1
- data/lib/parsecom.rb +1 -0
- data/spec/parse_date_spec.rb +7 -0
- data/spec/spec_helper.rb +4 -0
- metadata +2 -2
data/lib/parse/date.rb
CHANGED
@@ -4,21 +4,33 @@ module Parse
|
|
4
4
|
include Util
|
5
5
|
|
6
6
|
class <<self
|
7
|
-
def parse
|
8
|
-
|
7
|
+
def parse *args
|
8
|
+
if args.size == 1 && args.first.is_a?(String)
|
9
|
+
new :iso => args.first
|
10
|
+
else
|
11
|
+
new.tap do |dt|
|
12
|
+
dt.time = Time.gm *args
|
13
|
+
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
|
18
|
+
attr_accessor :time
|
19
|
+
|
12
20
|
def initialize hash={}
|
13
21
|
hash = string_keyed_hash hash
|
14
22
|
@raw_hash = hash
|
15
23
|
@time = ::Time.parse hash['iso'] if hash.has_key? 'iso'
|
16
24
|
end
|
17
25
|
|
26
|
+
def <=> other
|
27
|
+
self.time <=> other.time
|
28
|
+
end
|
29
|
+
|
18
30
|
def to_h
|
19
31
|
{
|
20
32
|
"__type" => "Date",
|
21
|
-
"iso" => @time.
|
33
|
+
"iso" => @time.iso8601
|
22
34
|
}
|
23
35
|
end
|
24
36
|
|
@@ -34,4 +46,10 @@ module Parse
|
|
34
46
|
@time.__send__ name, *args, &block
|
35
47
|
end
|
36
48
|
end
|
49
|
+
|
50
|
+
module_function
|
51
|
+
|
52
|
+
def date *args
|
53
|
+
ParseDate.parse *args
|
54
|
+
end
|
37
55
|
end
|
data/lib/parse/object.rb
CHANGED
@@ -52,7 +52,9 @@ module Parse
|
|
52
52
|
raw_results = parse_client.find(self.parse_class_name, object_id_or_conditions, opts)
|
53
53
|
results = [raw_results].flatten
|
54
54
|
results.map! {|hash| self.new hash} # TODO: should be recursive
|
55
|
-
|
55
|
+
if raw_results.is_a? Array
|
56
|
+
results.query_count = raw_results.query_count
|
57
|
+
end
|
56
58
|
results
|
57
59
|
end
|
58
60
|
|
@@ -65,7 +67,9 @@ module Parse
|
|
65
67
|
raw_results = parse_client.find!(self.parse_class_name, object_id_or_conditions, opts)
|
66
68
|
results = [raw_results].flatten
|
67
69
|
results.map! {|hash| self.new hash}
|
68
|
-
|
70
|
+
if raw_results.is_a? Array
|
71
|
+
results.query_count = raw_results.query_count
|
72
|
+
end
|
69
73
|
results
|
70
74
|
end
|
71
75
|
|
data/lib/parse/query.rb
CHANGED
@@ -203,6 +203,14 @@ module Parse
|
|
203
203
|
alias greater_that_or_equal_to gte
|
204
204
|
alias not_equal_to ne
|
205
205
|
|
206
|
+
def between range
|
207
|
+
if range.exclude_end?
|
208
|
+
self.gt(range.begin).lt(range.end)
|
209
|
+
else
|
210
|
+
self.gte(range.begin).lte(range.end)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
206
214
|
def exists val=true
|
207
215
|
@conditions.push ['$exists', val]
|
208
216
|
self
|
@@ -212,6 +220,9 @@ module Parse
|
|
212
220
|
%w(in nin all).each do |op|
|
213
221
|
eval %Q{
|
214
222
|
def #{op} *vals
|
223
|
+
if vals.size == 1 && vals.first.is_a?(Array)
|
224
|
+
vals = vals.first
|
225
|
+
end
|
215
226
|
@conditions.push ['$#{op}', vals]
|
216
227
|
self
|
217
228
|
end
|
data/lib/parse/version.rb
CHANGED
data/lib/parsecom.rb
CHANGED
data/spec/parse_date_spec.rb
CHANGED
@@ -10,6 +10,13 @@ describe Parse::ParseDate, 'when converting from and to json' do
|
|
10
10
|
date.to_json.should == '{"__type":"Date","iso":"2013-10-18T20:53:25Z"}'
|
11
11
|
end
|
12
12
|
|
13
|
+
it 'should be converted to a correct json' do
|
14
|
+
date = Parse::ParseDate.parse 2013, 10, 18, 20, 53, 25
|
15
|
+
date.year.should == 2013
|
16
|
+
date.month.should == 10
|
17
|
+
date.to_json.should == '{"__type":"Date","iso":"2013-10-18T20:53:25Z"}'
|
18
|
+
end
|
19
|
+
|
13
20
|
it 'should be converted from a json' do
|
14
21
|
date = Parse::ParseDate.new :iso => '2013-10-18T20:53:25Z'
|
15
22
|
date.year.should == 2013
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsecom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|