act_as_fire_record_beta 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f91046f509170198a4f91b0530f583bfe4dcf525d860f4951dd42c53d8511cd3
4
- data.tar.gz: 8ffec0b70b05f93b64a8f6ebe4399d8d85478782f43d8dcb8adf8f49d8ce463b
3
+ metadata.gz: 7fa5ffce208135ba537f2eba3ae37caf239e6b49446f2d31c77668263ec178c3
4
+ data.tar.gz: c4705cc8018288e15a766bd7efde203fdb03d701db208a66cbb46409732b1077
5
5
  SHA512:
6
- metadata.gz: 07da3548becfcd449bf53f4d056fbea0a7eadf9012f984dd7274a08805e41b51e6dbc287ddb3c48fa89ad9c5f6c50d1850fe1b6af2d91ea472c6230107857965
7
- data.tar.gz: a9f732055b79f3ae0985c2b7d2c6f6c4c42dd63923cae92bef16a5473f4631f6b43219ca5cc507a6c0fa6ec6459826cf9e887591aa6c5ca668225ee12c6f4434
6
+ metadata.gz: 382202705f5383d954bfd336137b6d74e0bf66879a3a07e8a480e4ec3e1d9427bd35e5d23180a929c39c74ab8d7d2607eff70802a8f8c86f6825a7c6e3fedcfc
7
+ data.tar.gz: '01158cd356bae1b962f62ba6575d52fb9e5648d83dc501ab8e3d0aaf2c19bffe6a5f1501aa17206a3f6f8f71a3f841370b5f7295aa8c19a07faecc249de319ab'
@@ -2,36 +2,26 @@ module Google
2
2
  module Cloud
3
3
  module Firestore
4
4
  class Query
5
- def find_one(&block)
6
- find_many(limit: 1, &block)[0]
7
- end
8
-
9
- def find_one!(&block)
10
- find_one(&block) || raise(ActiveRecord::RecordNotFound)
11
- end
12
-
13
- def find_many(limit: nil, &block)
5
+ def get_records(limit: nil)
14
6
  scope = limit ? limit(limit) : self
15
7
  scope.get.map do |data|
16
8
  model_lass = ActAsFireRecordBeta.class_mapping[query.from[0].collection_id]
17
- record = model_lass.to_instance(data)
18
- block.call(record) if block
19
- record
9
+ model_lass.to_instance(data)
20
10
  end
21
11
  end
22
12
 
23
13
  def destroy_all
24
- find_many.each(&:destroy)
25
- end
26
-
27
- def exists?
28
- !!find_one
14
+ get_records.each(&:destroy)
29
15
  end
30
16
 
31
17
  def first(limit = 1)
32
- records = find_many(limit: limit)
18
+ records = get_records(limit: limit)
33
19
  limit == 1 ? records[0] : records
34
20
  end
21
+
22
+ def exists?
23
+ !!first
24
+ end
35
25
  end
36
26
  end
37
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActAsFireRecordBeta
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -43,8 +43,8 @@ module ActAsFireRecordBeta
43
43
  client.doc("#{collection_name_with_env}/#{id}")
44
44
  end
45
45
 
46
- def all(&block)
47
- col.find_many(&block)
46
+ def all
47
+ col.get_records
48
48
  end
49
49
 
50
50
  def find(id)
@@ -55,14 +55,14 @@ module ActAsFireRecordBeta
55
55
  end
56
56
 
57
57
  def find_by(param)
58
- raise ArgumentError, "param size should 1: #{param}" unless param.size == 1
58
+ raise ArgumentError, "param size should be 1: #{param}" unless param.size == 1
59
59
  field, value = param.to_a.flatten
60
60
 
61
- col.where(field, :==, value).limit(1).get do |data|
62
- return to_instance(data)
63
- end
61
+ where(field, :==, value).first
62
+ end
64
63
 
65
- nil
64
+ def find_by!(param)
65
+ find_by(param) || raise(ActiveRecord::RecordNotFound)
66
66
  end
67
67
 
68
68
  def where(field, operator, value)
@@ -74,7 +74,7 @@ module ActAsFireRecordBeta
74
74
  end
75
75
 
76
76
  def first(limit = 1)
77
- records = col.find_many(limit: limit)
77
+ records = col.get_records(limit: limit)
78
78
  limit == 1 ? records[0] : records
79
79
  end
80
80
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act_as_fire_record_beta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichi Ito
@@ -69,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 2.6.0
72
+ version: 3.0.0
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="