activemodel-datastore 0.2.0 → 0.2.1

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: b11457bc388803b1f429027dd976ac9ed10250c9
4
- data.tar.gz: 52247ef1a1e9b49ee738d756374c441b00bd9488
3
+ metadata.gz: 1e463987e83057901c6622e91ed81f2b6c87e835
4
+ data.tar.gz: 2500a1f4714efeeecaa2ba0c6d5f46dd36a09ac9
5
5
  SHA512:
6
- metadata.gz: 8677a69f2faafa802c634829f01a86cc438295f157b71da0d431fe7bc3175f22154ecd03696a6d93444df42db86bd9d459d62271f5722b0b091c10d83e2bffa8
7
- data.tar.gz: 4caa657d528f99eb06963e028224a489ee3c9c3d44460b53336383422db86e8d3733f18c940854b75307cdf57ccb2a343a09d93d67084007332c02b5656fae27
6
+ metadata.gz: e18f47242c6c6e480845b24dd8aacb42477602ef815fb2b7496112b280f49bb48b3b15314b788981f34a613a74132c3ae36ae0a22d5d38403814ab93eb7c795d
7
+ data.tar.gz: 351cf7661a783efb53362838e045a1c4a7d1dfa45c4b434c35853c5a8fab9557b7ca444a68d4c0da646eb634da20d322b0c5fd619f3168def4a8fe04d2dd7c0f
@@ -1,3 +1,7 @@
1
+ ### 0.2.1 / 2017-04-25
2
+
3
+ * adding support for boolean types to format_property_value
4
+
1
5
  ### 0.2.0 / 2017-04-19
2
6
 
3
7
  * many documentation improvements
data/README.md CHANGED
@@ -8,8 +8,9 @@ Why would you want to use Google's NoSQL [Cloud Datastore](https://cloud.google.
8
8
  with Rails?
9
9
 
10
10
  When you want a Rails app backed by a managed, massively-scalable datastore solution. Cloud Datastore
11
- automatically handles sharding and replication, providing you with a highly available and durable
12
- database that scales automatically to handle your applications' load.
11
+ automatically handles sharding and replication. It is a highly available and durable database that
12
+ automatically scales to handle your applications' load. Cloud Datastore is a schemaless database
13
+ suited for unstructured or semi-structured application data.
13
14
 
14
15
  [![Gem Version](https://badge.fury.io/rb/activemodel-datastore.svg)](https://badge.fury.io/rb/activemodel-datastore)
15
16
 
@@ -235,10 +236,10 @@ and returns results with a cursor.
235
236
  ```ruby
236
237
  users = User.all(options = {})
237
238
 
238
- parent = CloudDatastore.dataset.key('Parent', 12345)
239
- users = User.all(ancestor: parent)
239
+ parent_key = CloudDatastore.dataset.key('Parent', 12345)
240
+ users = User.all(ancestor: parent_key)
240
241
 
241
- users = User.all(ancestor: parent, where: ['name', '=', 'Bryce'])
242
+ users = User.all(ancestor: parent_key, where: ['name', '=', 'Bryce'])
242
243
 
243
244
  users = User.all(where: [['name', '=', 'Ian'], ['enabled', '=', true]])
244
245
 
@@ -261,8 +262,8 @@ The parent key is optional. This method is a lookup by key and results will be s
261
262
  ```ruby
262
263
  user = User.find(1)
263
264
 
264
- parent = CloudDatastore.dataset.key('Parent', 12345)
265
- user = User.find(1, parent: parent)
265
+ parent_key = CloudDatastore.dataset.key('Parent', 12345)
266
+ user = User.find(1, parent: parent_key)
266
267
 
267
268
  users = User.find(1, 2, 3)
268
269
  ```
@@ -272,7 +273,7 @@ Queries for the first entity matching the specified condition.
272
273
  ```ruby
273
274
  user = User.find_by(name: 'Joe')
274
275
 
275
- user = User.find_by(name: 'Bryce', ancestor: parent)
276
+ user = User.find_by(name: 'Bryce', ancestor: parent_key)
276
277
  ```
277
278
 
278
279
  Cloud Datastore has documentation on how [Datastore Queries](https://cloud.google.com/datastore/docs/concepts/queries#datastore-basic-query-ruby)
@@ -115,6 +115,7 @@ module ActiveModel::Datastore
115
115
  include ActiveModel::Validations
116
116
  include ActiveModel::Validations::Callbacks
117
117
  include ActiveModel::Datastore::NestedAttr
118
+ include ActiveModel::Datastore::PropertyValues
118
119
  include ActiveModel::Datastore::TrackChanges
119
120
 
120
121
  included do
@@ -141,50 +142,6 @@ module ActiveModel::Datastore
141
142
  id.present?
142
143
  end
143
144
 
144
- ##
145
- # Sets a default value for the property if not currently set.
146
- #
147
- # Example:
148
- # default_property_value :state, 0
149
- #
150
- # is equivalent to:
151
- # self.state = state.presence || 0
152
- #
153
- # Example:
154
- # default_property_value :enabled, false
155
- #
156
- # is equivalent to:
157
- # self.enabled = false if enabled.nil?
158
- #
159
- def default_property_value(attr, value)
160
- if value.is_a?(TrueClass) || value.is_a?(FalseClass)
161
- send("#{attr.to_sym}=", value) if send(attr.to_sym).nil?
162
- else
163
- send("#{attr.to_sym}=", send(attr.to_sym).presence || value)
164
- end
165
- end
166
-
167
- ##
168
- # Converts the type of the property.
169
- #
170
- # Example:
171
- # format_property_value :weight, :float
172
- #
173
- # is equivalent to:
174
- # self.weight = weight.to_f if weight.present?
175
- #
176
- def format_property_value(attr, type)
177
- return unless send(attr.to_sym).present?
178
- case type.to_sym
179
- when :float
180
- send("#{attr.to_sym}=", send(attr.to_sym).to_f)
181
- when :integer
182
- send("#{attr.to_sym}=", send(attr.to_sym).to_i)
183
- else
184
- raise ArgumentError, 'Supported types are :float, :integer'
185
- end
186
- end
187
-
188
145
  ##
189
146
  # Builds the Cloud Datastore entity with attributes from the Model object.
190
147
  #
@@ -0,0 +1,53 @@
1
+ require 'active_model/type'
2
+
3
+ module ActiveModel::Datastore
4
+ module PropertyValues
5
+ extend ActiveSupport::Concern
6
+
7
+ ##
8
+ # Sets a default value for the property if not currently set.
9
+ #
10
+ # Example:
11
+ # default_property_value :state, 0
12
+ #
13
+ # is equivalent to:
14
+ # self.state = state.presence || 0
15
+ #
16
+ # Example:
17
+ # default_property_value :enabled, false
18
+ #
19
+ # is equivalent to:
20
+ # self.enabled = false if enabled.nil?
21
+ #
22
+ def default_property_value(attr, value)
23
+ if value.is_a?(TrueClass) || value.is_a?(FalseClass)
24
+ send("#{attr.to_sym}=", value) if send(attr.to_sym).nil?
25
+ else
26
+ send("#{attr.to_sym}=", send(attr.to_sym).presence || value)
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Converts the type of the property.
32
+ #
33
+ # Example:
34
+ # format_property_value :weight, :float
35
+ #
36
+ # is equivalent to:
37
+ # self.weight = weight.to_f if weight.present?
38
+ #
39
+ def format_property_value(attr, type)
40
+ return unless send(attr.to_sym).present?
41
+ case type.to_sym
42
+ when :integer
43
+ send("#{attr.to_sym}=", send(attr.to_sym).to_i)
44
+ when :float
45
+ send("#{attr.to_sym}=", send(attr.to_sym).to_f)
46
+ when :boolean
47
+ send("#{attr.to_sym}=", ActiveModel::Type::Boolean.new.cast(send(attr.to_sym)))
48
+ else
49
+ raise ArgumentError, 'Supported types are :boolean, :integer, :float'
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  module Datastore
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -6,7 +6,8 @@ require 'active_support/concern'
6
6
  require 'active_model'
7
7
 
8
8
  require 'active_model/datastore/connection'
9
- require 'active_model/datastore/track_changes'
10
- require 'active_model/datastore/nested_attr'
11
9
  require 'active_model/datastore/errors'
10
+ require 'active_model/datastore/nested_attr'
11
+ require 'active_model/datastore/property_values'
12
+ require 'active_model/datastore/track_changes'
12
13
  require 'active_model/datastore'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel-datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce McLean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -177,6 +177,7 @@ files:
177
177
  - lib/active_model/datastore/connection.rb
178
178
  - lib/active_model/datastore/errors.rb
179
179
  - lib/active_model/datastore/nested_attr.rb
180
+ - lib/active_model/datastore/property_values.rb
180
181
  - lib/active_model/datastore/track_changes.rb
181
182
  - lib/active_model/datastore/version.rb
182
183
  - lib/activemodel/datastore.rb