wolf_core 1.1.0 → 1.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db722de611536ac8908fc92df46aef74cdf6ac06388d6067a7d7decac2cb22c1
|
4
|
+
data.tar.gz: 81f5e2823ba6e0df5d3f9b190c56a4145d5c0213aaefadb1e756390ceeb0351e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0658df5828cf194bc6ea8509aee4c53511cfe0f2ed22c25100d60b66fbf9f833d2d267c44be5925a8d440c65749886126acf23deca689742dfdd382948e1187
|
7
|
+
data.tar.gz: 77d205bc4db37a4805b508d5586eec01218266dfcb501157f26fb3921daa4fedc5774b61ff0812c95606ce17e09dce787344e211fd25ea4808c73389ab7739fe
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WolfCore
|
4
|
+
class NoSqlDbInstanceDataSource
|
5
|
+
def self.init(region: "us-east-1")
|
6
|
+
return @instance if @instance
|
7
|
+
|
8
|
+
dynamodb_client = Aws::DynamoDB::Client.new(region: region)
|
9
|
+
@instance = new(client: dynamodb_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :instance
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(client:)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def put_item(table_name:, item:)
|
21
|
+
Result.try do
|
22
|
+
response = @client.put_item({
|
23
|
+
table_name: table_name,
|
24
|
+
item: item
|
25
|
+
})
|
26
|
+
Result.success(data: { response: response })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_item(table_name:, key:)
|
31
|
+
Result.try do
|
32
|
+
get_params = {
|
33
|
+
table_name: table_name,
|
34
|
+
key: key
|
35
|
+
}
|
36
|
+
item = @client.get_item(get_params).item
|
37
|
+
Result.success(data: { item: item })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_item_by_index(table_name:, key_condition_expression:, expression_attribute_values:, index_name: nil)
|
42
|
+
Result.try do
|
43
|
+
query(
|
44
|
+
table_name: table_name,
|
45
|
+
key_condition_expression: key_condition_expression,
|
46
|
+
expression_attribute_values: expression_attribute_values,
|
47
|
+
index_name: index_name,
|
48
|
+
limit: 1
|
49
|
+
).fold do |data|
|
50
|
+
items = data.items
|
51
|
+
Result.success(data: { item: items.first })
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def query(table_name:, key_condition_expression:, expression_attribute_values:, index_name: nil, limit: nil)
|
57
|
+
Result.try do
|
58
|
+
query_params = {
|
59
|
+
table_name: table_name,
|
60
|
+
key_condition_expression: key_condition_expression,
|
61
|
+
expression_attribute_values: expression_attribute_values
|
62
|
+
}
|
63
|
+
query_params[:index_name] = index_name if index_name
|
64
|
+
query_params[:limit] = limit if limit
|
65
|
+
|
66
|
+
items = @client.query(query_params).items
|
67
|
+
Result.success(data: { items: items })
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -129,9 +129,12 @@ module WolfCore
|
|
129
129
|
address
|
130
130
|
end
|
131
131
|
|
132
|
-
def split_name(full_name, name_range: nil, lastname_range: nil)
|
133
|
-
|
132
|
+
def split_name(full_name, name_range: nil, lastname_range: nil, if_one_word: nil)
|
133
|
+
if_one_word = {} unless if_one_word.is_a?(Hash)
|
134
|
+
if_one_word.merge!(lastname: "-") if if_one_word[:lastname].nil?
|
135
|
+
words = full_name.strip.split
|
134
136
|
|
137
|
+
return { first_name: words[0], last_name: if_one_word[:lastname] } if words.length == 1
|
135
138
|
return { first_name: words[0], last_name: words[1] } if words.length == 2
|
136
139
|
|
137
140
|
name_range ||= 0..-2
|
data/lib/wolf_core/version.rb
CHANGED
data/lib/wolf_core.rb
CHANGED
@@ -18,4 +18,5 @@ require 'wolf_core/utils/file_utils'
|
|
18
18
|
WolfCore::FileUtils.require_relative_folder(__dir__, 'wolf_core')
|
19
19
|
WolfCore::LambdaFunctionDataSource.init
|
20
20
|
WolfCore::InMemoryStorageDataSource.init
|
21
|
-
WolfCore::NoSqlDbDataSource.init
|
21
|
+
WolfCore::NoSqlDbDataSource.init
|
22
|
+
WolfCore::NoSqlDbInstanceDataSource.init
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolf_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Roncallo
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/wolf_core/infrastructure/lambda_function_data_source.rb
|
147
147
|
- lib/wolf_core/infrastructure/lambda_function_operations.rb
|
148
148
|
- lib/wolf_core/infrastructure/no_sql_db_data_source.rb
|
149
|
+
- lib/wolf_core/infrastructure/no_sql_db_instance_data_source.rb
|
149
150
|
- lib/wolf_core/infrastructure/no_sql_db_operations.rb
|
150
151
|
- lib/wolf_core/utils/array_utils.rb
|
151
152
|
- lib/wolf_core/utils/async_utils.rb
|