act_as_fire_record_beta 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/README.md +70 -3
- data/lib/act_as_fire_record_beta/version.rb +1 -1
- data/lib/act_as_fire_record_beta.rb +1 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c76e43b19f1342e88e1b20294590913587ac006c208181fa517c99f1023f1d00
|
4
|
+
data.tar.gz: 14f4ae4b3496befa9569837c0fa99fa902eb4b12d9c720a73ecf846913ef5ad1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 888b6e53584137db8793d626f8afd323474cd27473179a95c5253280cbf1ad21ecca33bd166f404821303a98aa6c8b69c4ac49f245e3e4e994d43a1dbbb55342
|
7
|
+
data.tar.gz: 9c0716e6bb104a0a526cd1e56229031a4f472c1ef1b0352a29e7e5e1126ff0b9af7720f09796c704b8f82aac2258d0822c98b45ae842dc31eade33c2a97c8509
|
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,74 @@ 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.get_records
|
72
|
+
|
73
|
+
books = Book.order(:title).get_records
|
74
|
+
books = Book.order(:title, :desc).get_records
|
75
|
+
|
76
|
+
books = Book.where(:page, :>=, 200).get_records
|
77
|
+
books = Book.where(:page, :>=, 200).order(:page).get_records
|
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
|
+
|
24
91
|
## Contributing
|
25
92
|
Contribution directions go here.
|
26
93
|
|
@@ -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?
|