act_as_fire_record_beta 0.0.6 → 0.0.8

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: 49ce18fcdd813103bc337ff059cb557688c2b9c56bd968154ca01f97faac94ae
4
- data.tar.gz: e0f2da2255f16d8da1c66309a89da90952541a80eb6e91375b047e912d944a5d
3
+ metadata.gz: c76e43b19f1342e88e1b20294590913587ac006c208181fa517c99f1023f1d00
4
+ data.tar.gz: 14f4ae4b3496befa9569837c0fa99fa902eb4b12d9c720a73ecf846913ef5ad1
5
5
  SHA512:
6
- metadata.gz: ba5bdc2b1ee0022524f463901a9505bee0bca3657a56ea9a2624f059e763e4307ffd72a0232346a54610cba674e19f95bf8c4b3dd3b68b653aed0f46ffaad0bf
7
- data.tar.gz: c96ee66f64cfa75506b18ca919332daf6df378dd19f7c0795b0c5c477a6c76d19b23d76fddddfc0e71570f1692e0429715f2bbbdd62d0645327c23c68c2433dc
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
- ## Usage
5
- How to use my plugin.
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
 
@@ -4,6 +4,25 @@ module ActAsFireRecordBeta
4
4
  require "act_as_fire_record_beta/google/cloud/firestore/query"
5
5
 
6
6
  ActionDispatch::ExceptionWrapper.rescue_responses["ActAsFireRecordBeta::RecordNotFound"] = :not_found
7
+
8
+ if Google::Cloud.configure.firestore.emulator_host
9
+ Google::Cloud::Firestore::V1::Firestore::Client.configure do |config|
10
+ config.rpcs.list_documents.metadata ||= {}
11
+ config.rpcs.list_documents.metadata['authorization'] = 'Bearer owner'
12
+ end
13
+
14
+ Google::Cloud::Firestore::Service.prepend(
15
+ Module.new do
16
+ protected
17
+
18
+ def default_headers parent = nil
19
+ headers = super
20
+ headers['authorization'] = 'Bearer owner'
21
+ headers
22
+ end
23
+ end
24
+ )
25
+ end
7
26
  end
8
27
  end
9
28
  end
@@ -1,3 +1,3 @@
1
1
  module ActAsFireRecordBeta
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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?
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.6
4
+ version: 0.0.8
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-10-29 00:00:00.000000000 Z
11
+ date: 2022-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.2.33
80
+ rubygems_version: 3.3.7
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: ActiveRecord like interface for Firestore