ocean-dynamo 0.3.1 → 0.3.2

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: e0600d1787ee17e3a8b0c3a3a46f6f5ba612a75e
4
- data.tar.gz: 00cf766c26b77d5e8bebdc73d98e02d440ef82d4
3
+ metadata.gz: 6f942e71fcd88e1e0971e48f931e62a686f1cf28
4
+ data.tar.gz: bb383ce780b0d04419de134073ea56d0bb6d3af7
5
5
  SHA512:
6
- metadata.gz: b48818cd86654ba5ad998121a824e046c73e1a4cdd8366d141f79f0f26ff6ba75d11c463bd7ede7dffe70a1463dde375ee2be5b4de33a9b08ffe4dfc93eb765c
7
- data.tar.gz: a8d5073f16ef39c346a38317b5ac0a28bdea0331be3f2ce55c45ff5757be7b798faf83959e03733360d7abf5d1e41ed3a49b2873919acee5fab32d6a66740b46
6
+ metadata.gz: b0f6617f8ed0224199f4b935f8faaa1e4ab54fa70086f6fec6834db564dbf4c61caad45f7de2a9a0a4d79aeb7199c17f30069864fbd383311cd304670210bca8
7
+ data.tar.gz: 6b6bcc33a0eb6f471f0d0d9654f12199b5255babf20c1a4028ef352b7e2ec32bbfffbf5b7db5d609ff807a693b9c0ff1ad190de47eb8735fe0e0f29255408917
@@ -40,7 +40,7 @@ The following example shows the syntax.
40
40
 
41
41
  class AsyncJob < OceanDynamo::Base
42
42
 
43
- dynamo_schema do
43
+ dynamo_schema(:uuid) do
44
44
  attribute :credentials, :string
45
45
  attribute :token
46
46
  attribute :steps, :serialized, default: []
@@ -62,8 +62,8 @@ The following example shows the syntax.
62
62
 
63
63
  Each attribute has a name, a type (+:string+, +:integer+, +:float+, +:datetime+, +:boolean+,
64
64
  or +:serialized+) where +:string+ is the default. Each attribute also optionally has a default
65
- value, which can be a Proc. The hash key attribute is by default +:uuid+ (this can of
66
- course be specified) and is a +:string+. The keys can also be explicitly declared.
65
+ value, which can be a Proc. The hash key attribute is by default +:id+ (overridden as :uuid in
66
+ the example above) and is a +:string+. The keys can also be explicitly declared.
67
67
 
68
68
  The +:string+, +:integer+, +:float+ and +:datetime+ types can also store sets of their type.
69
69
  Sets are represented as arrays, may not contain duplicates and may not be empty.
@@ -74,7 +74,7 @@ value will return the empty string, <tt>""</tt>.
74
74
  Also, dynamo_schema takes args and many options. Here's the full syntax:
75
75
 
76
76
  dynamo_schema(
77
- table_hash_key = :uuid, # The name of the hash key attribute
77
+ table_hash_key = :id, # The name of the hash key attribute
78
78
  table_range_key = nil, # The name of the range key attribute (or nil)
79
79
  table_name: compute_table_name, # The basename of the DynamoDB table
80
80
  table_name_prefix: nil, # A basename prefix string or nil
@@ -22,7 +22,7 @@ module OceanDynamo
22
22
  @new_record = true
23
23
  raise UnknownPrimaryKey unless table_hash_key
24
24
  end
25
- attrs && attrs.delete_if { |k, v| !fields.has_key?(k) }
25
+ attrs && attrs.delete_if { |k, v| !fields.has_key?(k) }
26
26
  super(attrs)
27
27
  end
28
28
 
@@ -38,7 +38,7 @@ module OceanDynamo
38
38
 
39
39
 
40
40
  def id
41
- read_attribute(table_hash_key)
41
+ read_attribute(table_hash_key)
42
42
  end
43
43
 
44
44
 
@@ -46,6 +46,10 @@ module OceanDynamo
46
46
  write_attribute(table_hash_key, value)
47
47
  end
48
48
 
49
+ def id?
50
+ read_attribute(table_hash_key).present?
51
+ end
52
+
49
53
 
50
54
  def read_attribute_for_validation(key)
51
55
  @attributes[key.to_s]
@@ -54,16 +58,18 @@ module OceanDynamo
54
58
 
55
59
  def read_attribute(attr_name)
56
60
  attr_name = attr_name.to_s
57
- if attr_name == 'id' && fields[table_hash_key] != attr_name.to_sym
58
- return read_attribute(table_hash_key)
61
+ attr_name = table_hash_key.to_s if attr_name == 'id'
62
+ if fields.has_key?(attr_name)
63
+ @attributes[attr_name]
64
+ else
65
+ raise ActiveModel::MissingAttributeError, "can't read unknown attribute `#{attr_ name}"
59
66
  end
60
- @attributes[attr_name] # Type cast!
61
67
  end
62
68
 
63
69
 
64
70
  def write_attribute(attr_name, value)
65
71
  attr_name = attr_name.to_s
66
- attr_name = table_hash_key.to_s if attr_name == 'id' && fields[table_hash_key]
72
+ attr_name = table_hash_key.to_s if attr_name == 'id'
67
73
  if fields.has_key?(attr_name)
68
74
  @attributes[attr_name] = type_cast_attribute_for_write(attr_name, value)
69
75
  else
@@ -80,7 +86,7 @@ module OceanDynamo
80
86
  end
81
87
 
82
88
 
83
- def assign_attributes(values)
89
+ def assign_attributes(values, without_protection: false)
84
90
  return if values.blank?
85
91
  values = values.stringify_keys
86
92
  # if values.respond_to?(:permitted?)
@@ -83,14 +83,14 @@ module OceanDynamo
83
83
  end
84
84
 
85
85
 
86
- def update_attributes(attrs={})
87
- assign_attributes(attrs)
86
+ def update_attributes(attrs={}, options={})
87
+ assign_attributes(attrs, options)
88
88
  save
89
89
  end
90
90
 
91
91
 
92
- def update_attributes!(attrs={})
93
- assign_attributes(attrs)
92
+ def update_attributes!(attrs={}, options={})
93
+ assign_attributes(attrs, options)
94
94
  save!
95
95
  end
96
96
 
@@ -16,6 +16,11 @@ module OceanDynamo
16
16
  end
17
17
 
18
18
 
19
+ def self.find_by_id(*args)
20
+ find_by_key(*args)
21
+ end
22
+
23
+
19
24
  def self.count
20
25
  _late_connect?
21
26
  dynamo_table.item_count || -1 # The || -1 is for fake_dynamo specs.
@@ -2,7 +2,7 @@ module OceanDynamo
2
2
  class Base
3
3
 
4
4
 
5
- def self.dynamo_schema(table_hash_key=:uuid,
5
+ def self.dynamo_schema(table_hash_key=:id,
6
6
  table_range_key=nil,
7
7
  table_name: compute_table_name,
8
8
  table_name_prefix: nil,
@@ -32,15 +32,17 @@ module OceanDynamo
32
32
  self.timestamp_attributes = timestamps
33
33
  # Init
34
34
  self.fields = HashWithIndifferentAccess.new
35
- attribute table_hash_key, :string, default: ''
35
+ attribute table_hash_key, :string, default: ""
36
36
  timestamp_attributes.each { |name| attribute name, :datetime } if timestamp_attributes
37
- attribute(lock_attribute, :integer, default: 0) if lock_attribute
37
+ attribute(lock_attribute, :integer, default: 0) if locking
38
38
  block.call
39
39
  # Define attribute accessors
40
40
  fields.each do |name, md|
41
- self.class_eval "def #{name}; read_attribute('#{name.to_s}'); end"
42
- self.class_eval "def #{name}=(value); write_attribute('#{name.to_s}', value); end"
43
- self.class_eval "def #{name}?; read_attribute('#{name.to_s}').present?; end"
41
+ name = name.to_s
42
+ # We define accessors even if the name is 'id' (for which we already have methods)
43
+ self.class_eval "def #{name}; read_attribute('#{name}'); end"
44
+ self.class_eval "def #{name}=(value); write_attribute('#{name}', value); end"
45
+ self.class_eval "def #{name}?; read_attribute('#{name}').present?; end"
44
46
  end
45
47
  # Connect to AWS
46
48
  establish_db_connection if connect == true
@@ -1,3 +1,3 @@
1
1
  module OceanDynamo
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-dynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk