ocean-dynamo 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bb66981fe7a08584a0a51f81e8cc458a354cac7
4
- data.tar.gz: d3ee6d39bfac9fe8622b91e7e485dbcbca16c8d3
3
+ metadata.gz: d38051cf48cd11c7a0dac98fcf9b9428e41d3d13
4
+ data.tar.gz: bb3df7327933a280a85f5c01214844e65c521c8b
5
5
  SHA512:
6
- metadata.gz: 4408c7038ebb322f96fd12d65b399f2dc7fdd59708a7f8d13659bba56b4996bb4987e9d052004e7cc0fa35c41e16548364ae87e7df9823adb5d2c03c0dc1ed29
7
- data.tar.gz: 29d4cdabc73cd9f84895cd9000c10099f001d56d5bffdfc92d0aab2dee4a4e1b66316e405945f38228814d40224e8ae91aabdcfbc9342da5ab57d51f297d13f5
6
+ metadata.gz: 1722be5b26ed320e782858b4842eb69aa24e29add54f019575e46fff97ff1a556c922de52390df2a5d6b859db2d6077d833742b852fedbaf938c5c15cfab3899
7
+ data.tar.gz: 9657f0d36b07e2b2d7ec4a036984dc3305f6121ee57648ac970da2b801e3ff37ffa7c5c98078fa937053619fdc81a96a71ad020090050bd4e7f9c2d09b038b38
@@ -7,7 +7,7 @@ module OceanDynamo
7
7
  [:created_at, :datetime],
8
8
  [:updated_at, :datetime],
9
9
  [:lock_version, :integer, default: 0]
10
- ]
10
+ ].freeze
11
11
 
12
12
  class DynamoError < StandardError; end
13
13
 
@@ -33,20 +33,37 @@ module OceanDynamo
33
33
  # ---------------------------------------------------------
34
34
 
35
35
  class_attribute :dynamo_client, instance_writer: false
36
+ self.dynamo_client = nil
37
+
36
38
  class_attribute :dynamo_table, instance_writer: false
39
+ self.dynamo_table = nil
40
+
37
41
  class_attribute :dynamo_items, instance_writer: false
42
+ self.dynamo_items = nil
38
43
 
39
44
  class_attribute :table_name, instance_writer: false
45
+ self.table_name = nil
46
+
40
47
  class_attribute :table_name_prefix, instance_writer: false
48
+ self.table_name_prefix = nil
49
+
41
50
  class_attribute :table_name_suffix, instance_writer: false
51
+ self.table_name_suffix = nil
42
52
 
43
53
  class_attribute :table_hash_key, instance_writer: false
54
+ self.table_hash_key = nil
55
+
44
56
  class_attribute :table_range_key, instance_writer: false
57
+ self.table_range_key = nil
45
58
 
46
59
  class_attribute :table_read_capacity_units, instance_writer: false
60
+ self.table_read_capacity_units = 10
61
+
47
62
  class_attribute :table_write_capacity_units, instance_writer: false
63
+ self.table_write_capacity_units = 5
48
64
 
49
65
  class_attribute :fields, instance_writer: false
66
+ self.fields = nil
50
67
 
51
68
 
52
69
  def self.set_table_name(name)
@@ -72,9 +89,20 @@ module OceanDynamo
72
89
  end
73
90
 
74
91
 
92
+ #
93
+ # This is where the class is initialized
94
+ #
75
95
  def self.primary_key(hash_key, range_key=nil)
96
+ self.dynamo_client = nil
97
+ self.dynamo_table = nil
98
+ self.dynamo_items = nil
99
+ self.table_name = nil
100
+ self.table_name_prefix = nil
101
+ self.table_name_suffix = nil
102
+ self.fields = HashWithIndifferentAccess.new
76
103
  self.table_hash_key = hash_key
77
104
  self.table_range_key = range_key
105
+ DEFAULT_FIELDS.each { |k, name, **pairs| field k, name, **pairs }
78
106
  # Find a better place to do the following initialisation:
79
107
  set_table_name compute_table_name unless self.table_name
80
108
  nil
@@ -99,7 +127,7 @@ module OceanDynamo
99
127
 
100
128
 
101
129
  def self.establish_db_connection
102
- setup_dynamo
130
+ setup_dynamo
103
131
  if dynamo_table.exists?
104
132
  wait_until_table_is_active
105
133
  else
@@ -112,6 +140,9 @@ module OceanDynamo
112
140
  def self.setup_dynamo
113
141
  #self.dynamo_client = AWS::DynamoDB::Client.new(:api_version => '2012-08-10')
114
142
  self.dynamo_client ||= AWS::DynamoDB.new
143
+
144
+ # TODO Create a non-inherited class accessor (SOLVE THAT PROBLEM!) called dynamo_tables
145
+
115
146
  self.dynamo_table = dynamo_client.tables[table_full_name]
116
147
  self.dynamo_items = dynamo_table.items
117
148
  end
@@ -215,19 +246,6 @@ module OceanDynamo
215
246
  define_model_callbacks :touch
216
247
 
217
248
 
218
- # ---------------------------------------------------------
219
- #
220
- # Class initialisation, done once at load time
221
- #
222
- # ---------------------------------------------------------
223
-
224
- self.table_read_capacity_units = 10
225
- self.table_write_capacity_units = 5
226
-
227
- self.fields = HashWithIndifferentAccess.new
228
- DEFAULT_FIELDS.each { |k, name, **pairs| Base.field k, name, **pairs }
229
-
230
-
231
249
  # ---------------------------------------------------------
232
250
  #
233
251
  # Instance variables and methods
@@ -251,15 +269,17 @@ module OceanDynamo
251
269
  self.class.class_eval "def #{name}?; read_attribute('#{name}'); end"
252
270
  end
253
271
  end
254
- if attrs
255
- attrs.delete_if { |k, v| !fields.has_key?(k) }
256
- end
257
- super(attrs)
272
+
258
273
  @dynamo_item = nil
259
274
  @destroyed = false
260
275
  @new_record = true
261
276
  raise NoPrimaryKeyDeclared unless table_hash_key
262
277
  end
278
+
279
+ if attrs
280
+ attrs.delete_if { |k, v| !fields.has_key?(k) }
281
+ end
282
+ super(attrs)
263
283
  end
264
284
 
265
285
 
@@ -1,3 +1,3 @@
1
1
  module OceanDynamo
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-dynamo
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
  - Peter Bengtson