dynamo-record 0.1.0 → 0.1.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: 77cdbe44e4be22d2294565970b108d66c48ffb87
4
- data.tar.gz: 70653d3d5cddc536eeefb74d47ea8522665f4b3b
3
+ metadata.gz: d18ec7a057cdce73f1f6e3f6aafa7b0175580be9
4
+ data.tar.gz: b12e97171dc6df596a9c787750c463741295c626
5
5
  SHA512:
6
- metadata.gz: b7fe3b6bd23079f734531545ee1ae42079d5053b99b058d9cc1c96a0ba78804de27b8f3fca6ed7609d299d7c20bf0bfd21c38b34823099b8da6cf254197c2537
7
- data.tar.gz: ec96773a915b361673ee1af591ea13a84b8cb5724cc5fc76168412d75cb43bd590d7b721462c2a682a677237459bc0449ee0c5e8f660806aa33097e3157c3731
6
+ metadata.gz: 509bdcf316a75601110e40ffaf80238d152c077d648f7433f4fef6566f458c9baad55e3cb66f75246166d54f2c9ab6e6f08b31128f92c0be6dac20dce47ff3ec
7
+ data.tar.gz: baf21793319609920a4526a027ebf2446a2af125e014717cf0493bcaa88ee97a0aad0af687fb1e4d5f892a0c342ed67afed9486006d0bab77c5bde3934010362
data/README.md CHANGED
@@ -107,4 +107,4 @@ module DynamoMigrate
107
107
  end
108
108
  end
109
109
  end
110
- ```
110
+ ```
@@ -1,122 +1,124 @@
1
1
  require 'aws-record'
2
2
 
3
- module DynamoRecord::Model
4
- COMPOSITE_DELIMITER = '|'.freeze
3
+ module DynamoRecord
4
+ module Model
5
+ COMPOSITE_DELIMITER = '|'.freeze
5
6
 
6
- def self.included(klass)
7
- klass.include(Aws::Record)
8
- klass.include(DynamoRecord::Marshalers)
7
+ def self.included(klass)
8
+ klass.include(Aws::Record)
9
+ klass.include(DynamoRecord::Marshalers)
9
10
 
10
- klass.extend ClassMethods
11
- klass.send :prepend, InstanceMethods
12
- end
13
-
14
- module ClassMethods
15
- def table_name
16
- [Rails.configuration.dynamo['prefix'], name.tableize].join('-').tr('/', '.')
11
+ klass.extend ClassMethods
12
+ klass.send :prepend, InstanceMethods
17
13
  end
18
14
 
19
- def scan
20
- raise 'no scanning in production' if Rails.env.production?
21
- super
22
- end
15
+ module ClassMethods
16
+ def table_name
17
+ [Rails.configuration.dynamo['prefix'], name.tableize].join('-').tr('/', '.')
18
+ end
23
19
 
24
- def find(opts)
25
- super(opts).tap do |record|
26
- unless record
27
- name = self.name.demodulize
28
- conditions = opts.map { |k, v| "#{k}=#{v}" }.join(', ')
29
- error = "Couldn't find #{name} with #{conditions}"
30
- raise Aws::Record::Errors::NotFound, error
31
- end
20
+ def scan
21
+ raise 'no scanning in production' if Rails.env.production?
22
+ super
32
23
  end
33
- end
34
24
 
35
- def find_all_by_hash_key(hash_key_value, opts = {})
36
- find_all_by_index_and_hash_key(hash_key, hash_key_value, opts)
37
- end
25
+ def find(opts)
26
+ super(opts).tap do |record|
27
+ unless record
28
+ name = self.name.demodulize
29
+ conditions = opts.map { |k, v| "#{k}=#{v}" }.join(', ')
30
+ error = "Couldn't find #{name} with #{conditions}"
31
+ raise Aws::Record::Errors::NotFound, error
32
+ end
33
+ end
34
+ end
38
35
 
39
- def find_all_by_gsi_hash_key(gsi_name, hash_key_value, opts = {})
40
- hash_key_name = global_secondary_indexes[gsi_name.to_sym][:hash_key]
41
- find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts, gsi_name.to_s)
42
- end
36
+ def find_all_by_hash_key(hash_key_value, opts = {})
37
+ find_all_by_index_and_hash_key(hash_key, hash_key_value, opts)
38
+ end
43
39
 
44
- def find_all_by_gsi_hash_and_range_keys(gsi_name, hash_key_value, range_key_value)
45
- gsi_config = global_secondary_indexes[gsi_name.to_sym]
46
- find_all_by_index_hash_and_range_keys(
47
- hash_config: { name: gsi_config[:hash_key], value: hash_key_value },
48
- range_config: { name: gsi_config[:range_key], value: range_key_value },
49
- index_name: gsi_name.to_s
50
- )
51
- end
40
+ def find_all_by_gsi_hash_key(gsi_name, hash_key_value, opts = {})
41
+ hash_key_name = global_secondary_indexes[gsi_name.to_sym][:hash_key]
42
+ find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts, gsi_name.to_s)
43
+ end
52
44
 
53
- def find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts = {}, index_name = nil)
54
- query_options = {
55
- select: 'ALL_ATTRIBUTES',
56
- key_condition_expression: "#{hash_key_name} = :hash_key_value",
57
- expression_attribute_values: {
58
- ':hash_key_value': hash_key_value
59
- },
60
- scan_index_forward: true
61
- }
62
- query_options[:index_name] = index_name if index_name
63
- query_options.merge!(opts)
64
- query(query_options)
65
- end
45
+ def find_all_by_gsi_hash_and_range_keys(gsi_name, hash_key_value, range_key_value)
46
+ gsi_config = global_secondary_indexes[gsi_name.to_sym]
47
+ find_all_by_index_hash_and_range_keys(
48
+ hash_config: { name: gsi_config[:hash_key], value: hash_key_value },
49
+ range_config: { name: gsi_config[:range_key], value: range_key_value },
50
+ index_name: gsi_name.to_s
51
+ )
52
+ end
66
53
 
67
- def find_all_by_index_hash_and_range_keys(hash_config:, range_config:, index_name: nil,
68
- scan_index_forward: true, limit: nil)
69
- query_options = {
70
- select: 'ALL_ATTRIBUTES',
71
- key_condition_expression: "#{hash_config[:name]} = :hkv AND #{range_config[:name]} = :rkv",
72
- expression_attribute_values: {
73
- ':hkv': hash_config[:value],
74
- ':rkv': range_config[:value]
75
- },
76
- scan_index_forward: scan_index_forward,
77
- limit: limit
78
- }
79
- query_options[:index_name] = index_name if index_name
80
- query(query_options)
81
- end
54
+ def find_all_by_index_and_hash_key(hash_key_name, hash_key_value, opts = {}, index_name = nil)
55
+ query_options = {
56
+ select: 'ALL_ATTRIBUTES',
57
+ key_condition_expression: "#{hash_key_name} = :hash_key_value",
58
+ expression_attribute_values: {
59
+ ':hash_key_value': hash_key_value
60
+ },
61
+ scan_index_forward: true
62
+ }
63
+ query_options[:index_name] = index_name if index_name
64
+ query_options.merge!(opts)
65
+ query(query_options)
66
+ end
82
67
 
83
- def composite_key(*args)
84
- args.join(COMPOSITE_DELIMITER)
85
- end
68
+ def find_all_by_index_hash_and_range_keys(hash_config:, range_config:, index_name: nil,
69
+ scan_index_forward: true, limit: nil)
70
+ query_options = {
71
+ select: 'ALL_ATTRIBUTES',
72
+ key_condition_expression: "#{hash_config[:name]} = :hkv AND #{range_config[:name]} = :rkv",
73
+ expression_attribute_values: {
74
+ ':hkv': hash_config[:value],
75
+ ':rkv': range_config[:value]
76
+ },
77
+ scan_index_forward: scan_index_forward,
78
+ limit: limit
79
+ }
80
+ query_options[:index_name] = index_name if index_name
81
+ query(query_options)
82
+ end
86
83
 
87
- def split_composite(string)
88
- string.split(COMPOSITE_DELIMITER)
89
- end
84
+ def composite_key(*args)
85
+ args.join(COMPOSITE_DELIMITER)
86
+ end
90
87
 
91
- def find_all_by_model(model, opts = {})
92
- find_all_by_hash_key(model.dynamo_key, opts)
93
- end
88
+ def split_composite(string)
89
+ string.split(COMPOSITE_DELIMITER)
90
+ end
94
91
 
95
- def find_all_by_model_paginated(model, opts = {})
96
- find_all_by_model(model, pagination_opts(opts))
97
- end
92
+ def find_all_by_model(model, opts = {})
93
+ find_all_by_hash_key(model.dynamo_key, opts)
94
+ end
98
95
 
99
- def pagination_opts(opts = {})
100
- { limit: opts[:limit], exclusive_start_key: opts[:exclusive_start_key] }
101
- end
96
+ def find_all_by_model_paginated(model, opts = {})
97
+ find_all_by_model(model, pagination_opts(opts))
98
+ end
102
99
 
103
- # TODO: Create a batch save method.
104
- end
100
+ def pagination_opts(opts = {})
101
+ { limit: opts[:limit], exclusive_start_key: opts[:exclusive_start_key] }
102
+ end
105
103
 
106
- module InstanceMethods
107
- def read_attribute_for_serialization(attribute)
108
- send(attribute)
104
+ # TODO: Create a batch save method.
109
105
  end
110
106
 
111
- def attribute_hash
112
- attrs = self.class.attributes.attributes
113
- attr_keys = attrs.keys
114
- hash = {}
107
+ module InstanceMethods
108
+ def read_attribute_for_serialization(attribute)
109
+ send(attribute)
110
+ end
111
+
112
+ def attribute_hash
113
+ attrs = self.class.attributes.attributes
114
+ attr_keys = attrs.keys
115
+ hash = {}
115
116
 
116
- attr_keys.each do |key|
117
- hash[key] = attrs[key].type_cast(send(key))
117
+ attr_keys.each do |key|
118
+ hash[key] = attrs[key].type_cast(send(key))
119
+ end
120
+ hash
118
121
  end
119
- hash
120
122
  end
121
123
  end
122
124
  end
@@ -1,5 +1,5 @@
1
1
  module DynamoRecord
2
2
  module Record
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamo-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davis McClellan
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2017-05-02 00:00:00.000000000 Z
16
+ date: 2017-05-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: aws-record