iseshima_store 0.1.3 → 0.1.4

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: e677b4e94938ba2ebb108ddff93bd1165fcaf852
4
- data.tar.gz: 6189431bd15b92d340c4722a79b9ecb2b21fac3f
3
+ metadata.gz: 071aa47fd9c81f21b21728e05fe2dc569a94b439
4
+ data.tar.gz: 31e2d1633a7ae4cbec512f6688a52915873c9264
5
5
  SHA512:
6
- metadata.gz: 52fdbaddd2045fe46114d6b64815bc2e295d253e030ba33b23dd2adeb5ec5b274094bb63f6ff7f04bcec769db84f888b26a1ec584dc8f939adb90e3f77d22c3b
7
- data.tar.gz: a8873566d8f87743350e9e5c8569f5918113c09c534f35c4cf68491a0d6dffe530a09a772d75472f7e16303ba42b27d4938166c539afac28834be27424d9fa00
6
+ metadata.gz: 007f22aea10c6d2d225c2a087f7c7f1be6b766ac0f8d6fa341c8f23176df718c9b0326e2ccfea6f85358aa668bfee981d0b0e58f5a2c6b8cfdbe122795b3c7e4
7
+ data.tar.gz: ae9da892271486c0674f6a01bf16861801a40f88a8c38973375d38a95128e86d8f5448a5d628d4f47a427ec918706550533947632a52fb985886271c6bef73da
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  You need to set project_id.
26
26
 
27
- ```
27
+ ```ruby
28
28
  IseshimaStore::Connection.configure do |config|
29
29
  config.project_id = 'xxxx'
30
30
  end
@@ -34,39 +34,80 @@ Iseshima Store depends on `gcloud-ruby` which uses ENV variables, you can set yo
34
34
 
35
35
  ### Model
36
36
 
37
- ```
37
+ ```ruby
38
38
  class User
39
39
  include IseshimaStore::Base
40
- attr_accessor :name, :email
40
+ attr_properties :name, :email
41
41
  end
42
42
  ```
43
43
 
44
- The only thing you have to do is just include `IseshimaStore::Base` in your model class.
44
+ The only thing you have to do is just 2 things.
45
+
46
+ 1. include `IseshimaStore::Base` in your model class.
47
+ 2. declare your properties with `attr_properties`
48
+
45
49
  Any class is ok to use.
46
50
 
47
51
  ### Create
48
52
 
49
- ```
53
+ ```ruby
50
54
  user = User.new
51
- user.email = 'test@test.com'
52
- user.name = 'hoge@fuga.com'
55
+ user.email = 'taro@test.com'
56
+ user.name = 'taro'
57
+ user.save!
58
+ ```
59
+
60
+ or
61
+
62
+ ```ruby
63
+ User.new.assign_attributes(
64
+ email: 'taro@test.com',
65
+ name: 'taro'
66
+ ).save!
67
+ ```
68
+
69
+ ### Save or Delete
70
+
71
+ ```
72
+ # save
73
+ user = User.first
74
+ user.assign_attributes(email: 'taro@test.jp')
53
75
  user.save!
76
+
77
+ # delete
78
+ user.destroy
54
79
  ```
55
80
 
56
- IseshimaStore does not have validations.
81
+ IseshimaStore does not have validations.
57
82
  Another gem like `ActiveModel` is recommended to combine.
58
83
 
59
84
  ### Finder
60
85
 
61
- ```
86
+ ```ruby
62
87
  users = User.where(email: 'test@test.com')
63
88
  user = User.find_by(email: 'test@test.com')
64
89
  user = User.find(12345) # id
90
+
91
+ # You can chain queries.
92
+ user = User.where(visible: true).find(10)
65
93
  ```
66
94
 
67
- ### Low level search
95
+ ### Relation
68
96
 
97
+
98
+ ```ruby
99
+ diary = Diary.new
100
+ diary.title = 'My nightmare'
101
+ diary.parent = user
102
+ diary.save!
69
103
  ```
104
+
105
+ `parent=(model)` sets model's key to the key's parent of instance.
106
+
107
+
108
+ ### Low level search
109
+
110
+ ```ruby
70
111
  query = Gcloud::Datastore::Query.new
71
112
  query.kind('User')
72
113
  query.where('email', '=', 'test@test.com')
@@ -77,8 +118,6 @@ users = res[:records]
77
118
  If you need `limit` & `cursor`, use this API.
78
119
 
79
120
 
80
-
81
-
82
121
  ## License
83
122
 
84
123
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -90,9 +90,6 @@ module IseshimaStore
90
90
  end
91
91
 
92
92
  def destroy
93
- if key.parent
94
- key.parent = nil
95
- end
96
93
  IseshimaStore::Connection.current.delete(key)
97
94
  end
98
95
 
@@ -146,7 +143,16 @@ module IseshimaStore
146
143
  end
147
144
 
148
145
  def key
149
- to_entity.key
146
+ path = []
147
+ obj = self
148
+ path << [obj.class.to_s, obj.id]
149
+
150
+ while obj.parent
151
+ obj = obj.parent
152
+ path << [obj.class.to_s, obj.id]
153
+ end
154
+
155
+ IseshimaStore::Connection.current.key(path.reverse)
150
156
  end
151
157
  end
152
158
  end
@@ -1,3 +1,3 @@
1
1
  module IseshimaStore
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iseshima_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kotohata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler