wolf_core 1.1.0 → 1.1.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 953b66fcc955d5b4ae8a2f1d17e3e4cc53d2ae21843fa72b1ace1df5823b064e
|
4
|
+
data.tar.gz: 8cdd27b6a73f40ea9cd4d4ee0127d4c9bb1b011cde46e1b2dfbd114a09a2e70e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5fd3fa9396960f9e67fb99a73c548eac336d8e169789785a8c60d4f3404c27895f0ec405bd25ecef632b9583d8baee5f07f122352996025babda4a15da53c3
|
7
|
+
data.tar.gz: 40c108d6eb259ce1676cbd33f9c305049f3082a2d5aa0410a4944e019796d41f3a8f3e247615cb8589655444da312660dd7d520b3cbb1be050e222ab71d9dc70
|
@@ -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,13 +129,21 @@ 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
|
138
141
|
lastname_range ||= -1..-1
|
142
|
+
log_object words, title: "split_name words are"
|
143
|
+
log_object name_range, title: "split_name name_range is"
|
144
|
+
log_object lastname_range, title: "split_name lastname_range is"
|
145
|
+
log_object words[name_range], title: "split_name words[name_range] is"
|
146
|
+
log_object words[lastname_range], title: "split_name words[lastname_range] is"
|
139
147
|
|
140
148
|
name = words[name_range].join(" ")
|
141
149
|
lastname = words[lastname_range].join(" ")
|
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.2
|
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
|