gdatastore_mapper 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/circle.yml +7 -0
- data/lib/gdatastore_mapper/base.rb +6 -4
- data/lib/gdatastore_mapper/persistence.rb +17 -11
- data/lib/gdatastore_mapper/version.rb +1 -1
- metadata +3 -3
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa320055068d5564fcdcc0b8096dce15383a35aa
|
4
|
+
data.tar.gz: 3fe5c73bdaafdbf425749d9a81e1eccf97a8619c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73593026c0db91d4794ce427d23a387ddae474ec86ea51a597a557f993f47cc0d3e5a1e86edc42e9b26c9e1284fd45db9f737453b583baef9cf0d74927ab90e4
|
7
|
+
data.tar.gz: 7aef4ddd1a987f6741ce9a97bc435bcd27cde748b6efd2b6035047c7f4bbb456829020ade488d95de5deee17b6b993d61f55e2fd16c3bfb84ff7c94c18d8d51c
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# GdatastoreMapper
|
2
|
+
[![CircleCI](https://circleci.com/gh/shinyaK14/gdatastore_mapper/tree/master.svg?style=svg)](https://circleci.com/gh/shinyaK14/gdatastore_mapper/tree/master) [![Gem Version](https://badge.fury.io/rb/gdatastore_mapper.svg)](https://badge.fury.io/rb/gdatastore_mapper)
|
2
3
|
|
3
4
|
GdatastoreMapper is a mapper framework for Google Cloud Datastore in Ruby / Ruby on Rails.
|
4
5
|
Once you install GdatastoreMapper you can use Google Cloud Datastore like ActiveRecord.
|
@@ -14,6 +15,8 @@ Once you install GdatastoreMapper you can use Google Cloud Datastore like Active
|
|
14
15
|
- [Timestamp](#timestamp)
|
15
16
|
- [Associations](#associations)
|
16
17
|
- [One to Many](#one-to-many)
|
18
|
+
- [Callbacks](#callbacks)
|
19
|
+
- [Contact](#contact)
|
17
20
|
- [Development](#development)
|
18
21
|
|
19
22
|
## Demo
|
@@ -152,6 +155,7 @@ All records have created_at and updated_at. They will be updated automatically.
|
|
152
155
|
## Associations
|
153
156
|
|
154
157
|
### One to Many
|
158
|
+
Associations can be set the same as Active Record.
|
155
159
|
|
156
160
|
example of one to many relationship
|
157
161
|
|
@@ -197,6 +201,27 @@ harry_poter.author
|
|
197
201
|
=> [#<Author:0x00 @name="J. K. Rowling" .... ]
|
198
202
|
```
|
199
203
|
|
204
|
+
## Callbacks
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
class Book
|
208
|
+
include GdatastoreMapper::Base
|
209
|
+
|
210
|
+
before_save :something_before_save
|
211
|
+
|
212
|
+
private
|
213
|
+
def something_before_save
|
214
|
+
something that you want
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
```
|
219
|
+
|
220
|
+
## Contact
|
221
|
+
|
222
|
+
Please shoot me an e-mail if you find any issues, ideas and comments. shinya.kitamura.14@gmail.com
|
223
|
+
Thanks!
|
224
|
+
|
200
225
|
## Development
|
201
226
|
|
202
227
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/circle.yml
ADDED
@@ -9,13 +9,15 @@ module GdatastoreMapper
|
|
9
9
|
include ActiveModel::Model
|
10
10
|
include ActiveModel::Validations
|
11
11
|
include ActiveModel::Validations::Callbacks
|
12
|
+
include ActiveModel::Callbacks
|
12
13
|
|
13
14
|
attr_accessor :id, :created_at, :updated_at
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
included do
|
17
|
+
define_model_callbacks :save, :update, :destroy
|
18
|
+
extend Scoping
|
19
|
+
extend Associations
|
20
|
+
include Persistence
|
19
21
|
end
|
20
22
|
|
21
23
|
module ClassMethods
|
@@ -3,24 +3,30 @@ module GdatastoreMapper
|
|
3
3
|
|
4
4
|
def save
|
5
5
|
return false if !valid?
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
run_callbacks :save do
|
7
|
+
entity = to_entity
|
8
|
+
GdatastoreMapper::Session.dataset.save(entity)
|
9
|
+
self.id = entity.key.id
|
10
|
+
update_owner(self, :add)
|
11
|
+
true
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
def update attributes
|
14
|
-
|
15
|
-
|
16
|
+
run_callbacks :update do
|
17
|
+
attributes.each do |name, value|
|
18
|
+
send "#{name}=", value if respond_to? "#{name}="
|
19
|
+
end
|
20
|
+
save
|
16
21
|
end
|
17
|
-
save
|
18
22
|
end
|
19
23
|
|
20
24
|
def destroy
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
run_callbacks :destroy do
|
26
|
+
update_owner(self, :delete)
|
27
|
+
GdatastoreMapper::Session.dataset.delete \
|
28
|
+
Google::Cloud::Datastore::Key.new self.class.to_s, id
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
def delete
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gdatastore_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinya Kitamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-datastore
|
@@ -103,7 +103,6 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
|
-
- ".travis.yml"
|
107
106
|
- CODE_OF_CONDUCT.md
|
108
107
|
- Gemfile
|
109
108
|
- LICENSE.txt
|
@@ -111,6 +110,7 @@ files:
|
|
111
110
|
- Rakefile
|
112
111
|
- bin/console
|
113
112
|
- bin/setup
|
113
|
+
- circle.yml
|
114
114
|
- gdatastore_mapper.gemspec
|
115
115
|
- lib/gdatastore_mapper.rb
|
116
116
|
- lib/gdatastore_mapper/associations.rb
|