act_as_fire_record_beta 0.0.7 → 0.0.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81eb3576251a5e99a7250637ee9b906a5b7c345338b7947db43dd1241e79d8b9
|
4
|
+
data.tar.gz: 15a2f9251f19d01d5a8e1ea58dcb45c0888440075e9ea827d585e7a5447c41c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 993a8bd4c0a4a032f1560954fb76eb5d03208e18a14c0fa2e35245d5199eebb3ed56d64ebf972dde770f37bfb6aed514c35df5b0d9cb29acfbcd18f6ee7073d3
|
7
|
+
data.tar.gz: 53ce442fff0fb9dd9c32c8e6edbf0994d105c60ed4e7476bb713c4e2508b4b98c2e88dcb2fe48308aa29cc6957aad1f0102f7258b386af02b4aa31d6825c996b
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# ActAsFireRecordBeta
|
2
|
-
Short description and motivation.
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
- Provides Rails applications with an ActiveRecord-like interface to manipulate Firestore.
|
4
|
+
- Works as a wrapper for the [google-cloud-firestore](https://rubygems.org/gems/google-cloud-firestore) gem.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
Add this line to your application's Gemfile:
|
@@ -21,6 +20,78 @@ Or install it yourself as:
|
|
21
20
|
$ gem install act_as_fire_record_beta
|
22
21
|
```
|
23
22
|
|
23
|
+
## Overview
|
24
|
+
|
25
|
+
Model example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class Book
|
29
|
+
include ActAsFireRecordBeta
|
30
|
+
|
31
|
+
firestore_attribute :title, :string
|
32
|
+
firestore_attribute :published_on, :date
|
33
|
+
firestore_attribute :page, :integer
|
34
|
+
|
35
|
+
validates :title, presence: true
|
36
|
+
|
37
|
+
before_validation :titleize_title
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def titleize_title
|
42
|
+
self.title = title.to_s.titleize
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
CRUD example:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# Create
|
51
|
+
book = Book.new(title: 'An Awesome Book', published_on: '2022-12-01'.to_date, page: 200)
|
52
|
+
book.save
|
53
|
+
bool.id #=> IdG0ZWT0I5DucEQuRgoP
|
54
|
+
|
55
|
+
# Read
|
56
|
+
id = 'IdG0ZWT0I5DucEQuRgoP'
|
57
|
+
book = Book.find(id)
|
58
|
+
|
59
|
+
# Update
|
60
|
+
book.update(page: 210)
|
61
|
+
|
62
|
+
# Delete
|
63
|
+
book.destroy
|
64
|
+
```
|
65
|
+
|
66
|
+
Finder examples:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
book = Book.find_by(title: 'An Awesome Book')
|
70
|
+
|
71
|
+
books = Book.all
|
72
|
+
|
73
|
+
books = Book.order(:title)
|
74
|
+
books = Book.order(:title, :desc)
|
75
|
+
|
76
|
+
books = Book.where(:page, :>=, 200)
|
77
|
+
books = Book.where(:page, :>=, 200).order(:page)
|
78
|
+
```
|
79
|
+
|
80
|
+
Please refer test codes for other APIs.
|
81
|
+
|
82
|
+
- https://github.com/JunichiIto/act_as_fire_record_beta/blob/main/test/act_as_fire_record_beta_test.rb
|
83
|
+
- https://github.com/JunichiIto/act_as_fire_record_beta/blob/main/test/google/cloud/firestore/query_test.rb
|
84
|
+
|
85
|
+
## Setup, usage and etc.
|
86
|
+
|
87
|
+
As of now, Japanese document is only available.
|
88
|
+
|
89
|
+
[README-ja.md](https://github.com/JunichiIto/act_as_fire_record_beta/blob/main/README-ja.md)
|
90
|
+
|
91
|
+
Google translate might help you.
|
92
|
+
|
93
|
+
[Auto-translated README-ja.md](https://github-com.translate.goog/JunichiIto/act_as_fire_record_beta/blob/main/README-ja.md?_x_tr_sl=ja&_x_tr_tl=en&_x_tr_hl=ja&_x_tr_pto=wapp)
|
94
|
+
|
24
95
|
## Contributing
|
25
96
|
Contribution directions go here.
|
26
97
|
|
@@ -2,20 +2,36 @@ module Google
|
|
2
2
|
module Cloud
|
3
3
|
module Firestore
|
4
4
|
class Query
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def method_missing(sym, *args)
|
8
|
+
if respond_to_missing?(sym, false)
|
9
|
+
self.to_a.send(sym, *args)
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to_missing?(sym, _include_private)
|
16
|
+
[].respond_to?(sym) ? true : super
|
17
|
+
end
|
18
|
+
|
19
|
+
def each(&b)
|
20
|
+
records = get.map do |data|
|
21
|
+
record = fire_record_class.to_instance(data)
|
22
|
+
b.call(record) if b
|
23
|
+
record
|
9
24
|
end
|
25
|
+
b ? records : records.each
|
10
26
|
end
|
11
27
|
|
12
28
|
def destroy_all
|
13
|
-
doc_refs =
|
29
|
+
doc_refs = self.map(&:doc_ref)
|
14
30
|
fire_record_class.delete_in_batch(doc_refs)
|
15
31
|
end
|
16
32
|
|
17
33
|
def first(limit = 1)
|
18
|
-
records =
|
34
|
+
records = limit(limit)
|
19
35
|
limit == 1 ? records[0] : records
|
20
36
|
end
|
21
37
|
|
@@ -48,15 +48,12 @@ module ActAsFireRecordBeta
|
|
48
48
|
def col
|
49
49
|
@_col ||= client.col(collection_name_with_env)
|
50
50
|
end
|
51
|
+
alias all col
|
51
52
|
|
52
53
|
def doc(id)
|
53
54
|
client.doc("#{collection_name_with_env}/#{id}")
|
54
55
|
end
|
55
56
|
|
56
|
-
def all
|
57
|
-
col.get_records
|
58
|
-
end
|
59
|
-
|
60
57
|
def find(id)
|
61
58
|
data = doc(id).get
|
62
59
|
raise ActAsFireRecordBeta::RecordNotFound, "Couldn't find record with #{self} with 'id'='#{id}'" if data.missing?
|
@@ -84,8 +81,11 @@ module ActAsFireRecordBeta
|
|
84
81
|
end
|
85
82
|
|
86
83
|
def first(limit = 1)
|
87
|
-
|
88
|
-
|
84
|
+
all.first(limit)
|
85
|
+
end
|
86
|
+
|
87
|
+
def count
|
88
|
+
all.count
|
89
89
|
end
|
90
90
|
|
91
91
|
def create(params)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Junichi Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|