gdatastore_mapper 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37b4099d9d73578ac345308631870169d1e24513
4
- data.tar.gz: 65d545b40e2b8482f7033c2e53e195a869aa88d5
3
+ metadata.gz: aa320055068d5564fcdcc0b8096dce15383a35aa
4
+ data.tar.gz: 3fe5c73bdaafdbf425749d9a81e1eccf97a8619c
5
5
  SHA512:
6
- metadata.gz: d17c543ebd171c76fd20dd5aa78ba860a3765c4741762331d9fbaa22bb6207010cf2b66e2accabda4e017af4e8f7ee566f22ee46d4863ac2065bea97f162c48d
7
- data.tar.gz: b4af8479645b8b161b2cd74d61b699b4c9361a6e3f260291a45f9838f56085b1a5e6918d7e379a0363234c841d53dce3a077e57f633dc22d2dd587f7e5f1eb5e
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
@@ -0,0 +1,7 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.3
4
+
5
+ dependencies:
6
+ pre:
7
+ - mv spec/config/database.yml.ci spec/config/database.yml
@@ -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
- def self.included(klass)
16
- klass.extend Scoping
17
- klass.extend Associations
18
- klass.include Persistence
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
- entity = to_entity
7
- GdatastoreMapper::Session.dataset.save(entity)
8
- self.id = entity.key.id
9
- update_owner(self, :add)
10
- true
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
- attributes.each do |name, value|
15
- send "#{name}=", value if respond_to? "#{name}="
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
- update_owner(self, :delete)
22
- GdatastoreMapper::Session.dataset.delete \
23
- Google::Cloud::Datastore::Key.new self.class.to_s, id
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
@@ -1,3 +1,3 @@
1
1
  module GdatastoreMapper
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
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
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-18 00:00:00.000000000 Z
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
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.14.6