sink-base 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 91e2482265ef1b14d8f139b0ac3debdc0ce01ac0bafca864d874aca7bb27a1c0
4
+ data.tar.gz: 187902389bf225a37eaa561c6c5ca6b9175289976146898db59c0e34a1028163
5
+ SHA512:
6
+ metadata.gz: 20f7f9b107b470de5e219a12fce1ae86c16d6c8e837ae665feeb6f71a55048638af3e0df9cab523443d741fc7b79775b654c14f678c63e243d1709426e2222d8
7
+ data.tar.gz: 5e8b4c14187cabdb9812b2876d42bb5b76ea57c9b4af9c9aa0907b4de698ca8898bbf3b1d21e9d4b944a202b030b5ff4d36172d14c4906bbe9605e319025b8e6
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sink-base.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sink-base (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ aws-eventstream (1.1.0)
10
+ aws-partitions (1.424.0)
11
+ aws-sdk-core (3.112.0)
12
+ aws-eventstream (~> 1, >= 1.0.2)
13
+ aws-partitions (~> 1, >= 1.239.0)
14
+ aws-sigv4 (~> 1.1)
15
+ jmespath (~> 1.0)
16
+ aws-sdk-dynamodb (1.59.0)
17
+ aws-sdk-core (~> 3, >= 3.112.0)
18
+ aws-sigv4 (~> 1.1)
19
+ aws-sigv4 (1.2.2)
20
+ aws-eventstream (~> 1, >= 1.0.2)
21
+ diff-lcs (1.4.4)
22
+ jmespath (1.4.0)
23
+ rake (12.3.3)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.2)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.2)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ aws-sdk-dynamodb (~> 1)
43
+ rake (~> 12.0)
44
+ rspec (~> 3.0)
45
+ sink-base!
46
+
47
+ BUNDLED WITH
48
+ 2.1.2
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Sink::Base
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sink/base`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sink-base'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sink-base
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sink-base.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sink/base"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/sink/base.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "sink/base/version"
2
+
3
+ module Sink
4
+ module Base
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,72 @@
1
+ require 'aws-sdk-dynamodb'
2
+
3
+ module Sink
4
+ module Base
5
+ module Dao
6
+ class QaDao
7
+ TABLE_NAME = 'sink'
8
+ GSI1 = 'GSI1'
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ def total_count(qa_category)
15
+ query_spec = {
16
+ table_name: TABLE_NAME,
17
+ index_name: GSI1,
18
+ key_condition_expression: 'sk = :v_sk',
19
+ expression_attribute_values: {
20
+ ':v_sk' => qa_category,
21
+ },
22
+ scan_index_forward: false,
23
+ limit: 1,
24
+ select: "ALL_ATTRIBUTES"
25
+ }
26
+
27
+ resp = @client.query(query_spec)
28
+ return 0 if resp.count.zero?
29
+
30
+ resp.items[0]['data'].to_i
31
+ end
32
+
33
+ def get_by_table_index(id, qa_category, fields=[])
34
+ resp = @client.get_item(
35
+ key: {
36
+ 'pk' => id,
37
+ 'sk' => qa_category,
38
+ },
39
+ table_name: TABLE_NAME,
40
+ )
41
+
42
+ item = resp.item
43
+ return nil if item.nil?
44
+ fields.empty? ? item : item.slice(*fields)
45
+ end
46
+
47
+ def find_first_by_gsi1(qa_category, sequence, fields=[])
48
+ query_spec = {
49
+ table_name: TABLE_NAME,
50
+ index_name: GSI1,
51
+ key_condition_expression: 'sk = :v_sk AND #data = :v_data',
52
+ expression_attribute_names: {
53
+ '#data' => 'data',
54
+ },
55
+ expression_attribute_values: {
56
+ ':v_sk' => qa_category,
57
+ ':v_data' => sequence
58
+ },
59
+ limit: 1,
60
+ select: "ALL_ATTRIBUTES"
61
+ }
62
+
63
+ resp = @client.query(query_spec)
64
+ return nil if resp.count.zero?
65
+
66
+ item = resp.items[0]
67
+ fields.empty? ? item : item.slice(*fields)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Sink
2
+ module Base
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
data/sink-base.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/sink/base/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sink-base"
5
+ spec.version = Sink::Base::VERSION
6
+ spec.authors = ["Xu Yunlong"]
7
+ spec.email = ["yunlox@amazon.com"]
8
+
9
+ spec.summary = "This is a common library for sink"
10
+ spec.description = "This is a common library for sink"
11
+ spec.homepage = "https://github.com/talexu/sink-base"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Dependency
30
+ spec.add_development_dependency 'aws-sdk-dynamodb', '~> 1'
31
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sink-base
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Xu Yunlong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-dynamodb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ description: This is a common library for sink
28
+ email:
29
+ - yunlox@amazon.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - lib/sink/base.rb
44
+ - lib/sink/base/dao/qa_dao.rb
45
+ - lib/sink/base/version.rb
46
+ - sink-base.gemspec
47
+ homepage: https://github.com/talexu/sink-base
48
+ licenses: []
49
+ metadata:
50
+ allowed_push_host: https://rubygems.org
51
+ homepage_uri: https://github.com/talexu/sink-base
52
+ source_code_uri: https://github.com/talexu/sink-base
53
+ changelog_uri: https://github.com/talexu/sink-base
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: This is a common library for sink
73
+ test_files: []