neuromancer-indexer 0.3.0 → 0.4.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
- SHA1:
3
- metadata.gz: bfeb244c643ecd7751c471d2bcfa6c0c2d83f3ca
4
- data.tar.gz: 474fe0b12cb2600926689dd5355299f60e52249f
2
+ SHA256:
3
+ metadata.gz: f76b29711a1de358acaadfe86774796d81d912133e67d65b03cc5a3cbf622cd8
4
+ data.tar.gz: 3bf9160dfe06c129eac287f74ff4ac6d6823eb942103e96828034ab3f888ee28
5
5
  SHA512:
6
- metadata.gz: 4f724edc9577bf9053691caefdc4fc27e880ca59bc30b77c8be5618b1d76ac8fa427a4045770e6f919eb7728bb0a543f6606b8b93ad3d830a5e0bdd66d215b94
7
- data.tar.gz: d9e4476c2542d9fd38329c10a0b9a3cf36c6ab140212e818c3643d7cb0ab2339eb0ec75e2a9af7be741697849958c5d4c7228c8c8caf45b7f641e17d752089e0
6
+ metadata.gz: fb394dd151dfa324bfe5825e32f49a2793e1fc180cc277c3121a1f8e99cc5a4c0849199dbc0401df630413e901c16574c8a15c8e564304c2e3128a1f3abb28e6
7
+ data.tar.gz: 8af32893e9d39ff3afc76227e4fba269d9bdb2b46399846dda0423b9020896044b31706ec50c8d5b4adb73c0d823c43b040608bff1ede779c1f0686eeff3d4b3
@@ -0,0 +1,46 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ ruby-gem:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby 2.6
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6
19
+
20
+ - name: Install dependencies
21
+ run: |
22
+ gem install bundler
23
+ bundle install
24
+
25
+ - name: Push to GitHub Package Repository
26
+ run: |
27
+ mkdir -p $HOME/.gem
28
+ touch $HOME/.gem/credentials
29
+ chmod 0600 $HOME/.gem/credentials
30
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
31
+ gem build *.gemspec
32
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
33
+ env:
34
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
35
+ OWNER: ${{ github.repository_owner }}
36
+
37
+ - name: Push to RubyGems
38
+ run: |
39
+ mkdir -p $HOME/.gem
40
+ touch $HOME/.gem/credentials
41
+ chmod 0600 $HOME/.gem/credentials
42
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
43
+ gem build *.gemspec
44
+ gem push *.gem
45
+ env:
46
+ GEM_HOST_API_KEY: "Bearer ${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,43 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+
7
+ name: Tests
8
+
9
+ on:
10
+ push:
11
+ branches: [ develop ]
12
+ pull_request:
13
+
14
+ jobs:
15
+ rspec:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby 2.6
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.6
23
+ - name: Install dependencies
24
+ run: |
25
+ gem install bundler
26
+ bundle install
27
+ - name: Run RSpec
28
+ run: bundle exec rspec
29
+
30
+ rubocop:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ - name: Set up Ruby 2.6
35
+ uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: 2.6
38
+ - name: Install dependencies
39
+ run: |
40
+ gem install bundler
41
+ bundle install
42
+ - name: Run Rubocop
43
+ run: bundle exec rubocop
@@ -0,0 +1,56 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+ AllCops:
13
+ TargetRubyVersion: 2.5
14
+ Exclude:
15
+ - 'bin/*'
16
+ - 'node_modules/**/*'
17
+ - 'vendor/**/*'
18
+ - 'spec/**/*'
19
+
20
+ Layout/EmptyLinesAroundAttributeAccessor:
21
+ Enabled: true
22
+ Layout/SpaceAroundMethodCallOperator:
23
+ Enabled: true
24
+
25
+ Lint/DeprecatedOpenSSLConstant:
26
+ Enabled: true
27
+ Lint/MixedRegexpCaptureTypes:
28
+ Enabled: true
29
+ Lint/RaiseException:
30
+ Enabled: true
31
+ Lint/StructNewOverride:
32
+ Enabled: true
33
+
34
+ Metrics/MethodLength:
35
+ Enabled: false
36
+ Metrics/ModuleLength:
37
+ Enabled: false
38
+
39
+ Style/Documentation:
40
+ Enabled: false
41
+ Style/ExponentialNotation:
42
+ Enabled: true
43
+ Style/HashEachMethods:
44
+ Enabled: true
45
+ Style/HashTransformKeys:
46
+ Enabled: true
47
+ Style/HashTransformValues:
48
+ Enabled: true
49
+ Style/RedundantFetchBlock:
50
+ Enabled: true
51
+ Style/RedundantRegexpCharacterClass:
52
+ Enabled: true
53
+ Style/RedundantRegexpEscape:
54
+ Enabled: true
55
+ Style/SlicingWithRange:
56
+ Enabled: true
@@ -1,5 +1,9 @@
1
1
  ## Changelog
2
2
 
3
+ #### 0.4.2
4
+ - add `Neuromancer::Indexer.delete`
5
+ - add GitHub workflows for `RSpec`, `Rubocop` and `RubyGems`
6
+
3
7
  #### 0.3.0
4
8
  - optionally use AWS user credentials for SQS instead of role credentials
5
9
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # neuromancer-indexer
2
2
 
3
- [![Build Status](https://travis-ci.com/jdahlke/neuromancer-indexer.svg?branch=develop)](https://travis-ci.com/jdahlke/neuromancer-indexer)
3
+ [![GitHub Actions Test Status](https://github.com/jdahlke/neuromancer-indexer/workflows/Tests/badge.svg?branch=develop)](https://github.com/jdahlke/neuromancer-indexer/actions)
4
4
 
5
5
  Ruby gem to push data for indexing to the Neuromancer service
6
6
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rspec/core'
@@ -7,6 +7,7 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ ast (2.4.1)
10
11
  aws-eventstream (1.0.3)
11
12
  aws-partitions (1.226.0)
12
13
  aws-sdk-core (3.69.1)
@@ -21,7 +22,13 @@ GEM
21
22
  aws-eventstream (~> 1.0, >= 1.0.2)
22
23
  diff-lcs (1.3)
23
24
  jmespath (1.4.0)
24
- rake (10.5.0)
25
+ parallel (1.19.2)
26
+ parser (2.7.1.4)
27
+ ast (~> 2.4.1)
28
+ rainbow (3.0.0)
29
+ rake (13.0.1)
30
+ regexp_parser (1.7.1)
31
+ rexml (3.2.4)
25
32
  rspec (3.9.0)
26
33
  rspec-core (~> 3.9.0)
27
34
  rspec-expectations (~> 3.9.0)
@@ -35,15 +42,29 @@ GEM
35
42
  diff-lcs (>= 1.2.0, < 2.0)
36
43
  rspec-support (~> 3.9.0)
37
44
  rspec-support (3.9.0)
45
+ rubocop (0.86.0)
46
+ parallel (~> 1.10)
47
+ parser (>= 2.7.0.1)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ regexp_parser (>= 1.7)
50
+ rexml
51
+ rubocop-ast (>= 0.0.3, < 1.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 1.4.0, < 2.0)
54
+ rubocop-ast (0.3.0)
55
+ parser (>= 2.7.1.4)
56
+ ruby-progressbar (1.10.1)
57
+ unicode-display_width (1.7.0)
38
58
 
39
59
  PLATFORMS
40
60
  ruby
41
61
 
42
62
  DEPENDENCIES
43
- bundler (~> 1.17.3)
63
+ bundler
44
64
  neuromancer-indexer!
45
- rake (~> 10.0)
65
+ rake (~> 13.0)
46
66
  rspec (~> 3.0)
67
+ rubocop (= 0.86.0)
47
68
 
48
69
  BUNDLED WITH
49
- 1.17.3
70
+ 2.1.4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in neuromancer-indexer.gemspec
@@ -1,13 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+ require 'aws-sdk-sqs'
5
+
3
6
  require 'neuromancer/indexer/version'
4
7
  require 'neuromancer/indexer/client'
8
+ require 'neuromancer/indexer/document'
5
9
  require 'neuromancer/indexer/configuration'
6
10
 
7
11
  module Neuromancer
8
12
  module Indexer
9
- class Error < StandardError; end
10
- class ConfigurationError < Error; end
13
+ class Error < StandardError
14
+ end
15
+
16
+ class ConfigurationError < Error
17
+ end
18
+
19
+ class InvalidDocument < Error
20
+ attr_reader :errors
21
+
22
+ def initialize(errors)
23
+ @errors = errors
24
+ end
25
+
26
+ def message
27
+ errors.join(', ')
28
+ end
29
+
30
+ def inspect
31
+ "#<#{self.class.name}: '#{message}'>"
32
+ end
33
+ end
11
34
 
12
35
  def self.config
13
36
  @config ||= Configuration.new
@@ -20,9 +43,16 @@ module Neuromancer
20
43
  config
21
44
  end
22
45
 
23
- def self.index(obj)
46
+ def self.client
24
47
  @client ||= Client.new
25
- @client.index(obj)
48
+ end
49
+
50
+ def self.index(obj)
51
+ client.index(obj)
52
+ end
53
+
54
+ def self.delete(obj)
55
+ client.delete(obj)
26
56
  end
27
57
  end
28
58
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'aws-sdk-sqs'
5
-
6
3
  module Neuromancer
7
4
  module Indexer
8
5
  class Client
@@ -13,15 +10,31 @@ module Neuromancer
13
10
  @sqs = sqs
14
11
  end
15
12
 
16
- def index(obj)
17
- message = obj.to_json
18
- validate_message!(message)
13
+ def index(id:, type:, body:)
14
+ document = Document.new(id: id, type: type, body: body)
15
+ document.validate!
16
+
17
+ enqueue(action: 'index', document: document)
18
+ end
19
+
20
+ def delete(id:, type:)
21
+ document = Document.new(id: id, type: type, body: {})
22
+ document.validate!
19
23
 
20
- sqs.send_message({
24
+ enqueue(action: 'delete', document: document)
25
+ end
26
+
27
+ def enqueue(action:, document:)
28
+ message = {
29
+ action: action,
30
+ document: document
31
+ }
32
+
33
+ sqs.send_message(
21
34
  queue_url: config.sqs_url,
22
- message_body: message,
35
+ message_body: message.to_json,
23
36
  delay_seconds: 1
24
- })
37
+ )
25
38
  end
26
39
 
27
40
  private
@@ -34,7 +47,7 @@ module Neuromancer
34
47
  options = {
35
48
  region: config.region
36
49
  }
37
- if config.access_key_id && config.secret_access_key
50
+ if present?(config.access_key_id) && present?(config.secret_access_key)
38
51
  options[:credentials] = Aws::Credentials.new(
39
52
  config.access_key_id,
40
53
  config.secret_access_key
@@ -44,23 +57,11 @@ module Neuromancer
44
57
  options
45
58
  end
46
59
 
47
- def validate_message!(message)
48
- hash = JSON.parse(message)
49
- id = hash['id'].to_s
50
- type = hash['type'].to_s
51
- body = hash['body']
52
-
53
- if id.empty?
54
- raise Error, 'Key `id` in obj cannot be empty'
55
- end
56
-
57
- if type.empty?
58
- raise Error, 'Key `type` in obj cannot be empty'
59
- end
60
+ def present?(value)
61
+ return false if value.nil?
62
+ return false if value.empty?
60
63
 
61
- if !body.is_a?(Hash)
62
- raise Error, 'Key `body` must be a Hash'
63
- end
64
+ true
64
65
  end
65
66
  end
66
67
  end
@@ -14,23 +14,17 @@ module Neuromancer
14
14
  end
15
15
 
16
16
  def validate!
17
- if region.to_s.empty?
18
- raise ConfigurationError, '`region` cannot be empty'
19
- end
17
+ raise ConfigurationError, '\'region\' cannot be empty' if region.to_s.empty?
20
18
 
21
- if sqs_url.to_s.empty?
22
- raise ConfigurationError, '`sqs_url` cannot be empty'
23
- end
19
+ raise ConfigurationError, '\'sqs_url\' cannot be empty' if sqs_url.to_s.empty?
24
20
 
21
+ invalid_protocol = '\'sqs_url\' must be a HTTPS url'
25
22
  begin
26
- if URI(sqs_url).scheme != 'https'
27
- raise ConfigurationError, '`sqs_url` must be a HTTPS url'
28
- end
29
- rescue => e
30
- raise ConfigurationError, '`sqs_url` must be a HTTPS url'
23
+ raise ConfigurationError, invalid_protocol if URI(sqs_url).scheme != 'https'
24
+ rescue StandardError
25
+ raise ConfigurationError, invalid_protocol
31
26
  end
32
27
  end
33
28
  end
34
29
  end
35
30
  end
36
-
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Neuromancer
4
+ module Indexer
5
+ class Document
6
+ attr_reader :id, :type, :body
7
+
8
+ def initialize(attributes)
9
+ @id = indifferent_value(attributes, :id).to_s
10
+ @type = indifferent_value(attributes, :type).to_s
11
+ @body = indifferent_value(attributes, :body)
12
+ end
13
+
14
+ def as_json
15
+ {
16
+ id: id,
17
+ type: type,
18
+ body: body
19
+ }
20
+ end
21
+
22
+ def validate!
23
+ errors = []
24
+
25
+ errors << 'document#id is empty' if id.empty?
26
+ errors << 'document#type is empty' if type.empty?
27
+ errors << 'document#body is not a Hash' unless body.is_a?(Hash)
28
+
29
+ raise(InvalidDocument, errors) unless errors.empty?
30
+ end
31
+
32
+ def indifferent_value(hash, key)
33
+ hash[key.to_sym] || hash[key.to_s]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Neuromancer
2
4
  module Indexer
3
- VERSION = '0.3.0'.freeze
5
+ VERSION = '0.4.2'
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'neuromancer/indexer/version'
@@ -12,19 +14,6 @@ Gem::Specification.new do |spec|
12
14
  spec.description = 'Ruby gem to push data for indexing to the Neuromancer service.'
13
15
  spec.homepage = 'https://github.com/jdahlke/neuromancer-indexer'
14
16
 
15
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
- # to allow pushing to a single host or delete this section to allow pushing to any host.
17
- if spec.respond_to?(:metadata)
18
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
-
20
- spec.metadata['homepage_uri'] = spec.homepage
21
- spec.metadata['source_code_uri'] = 'https://github.com/jdahlke/neuromancer-indexer'
22
- spec.metadata['changelog_uri'] = 'https://github.com/jdahlke/neuromancer-indexer/blob/master/CHANGELOG.md'
23
- else
24
- raise 'RubyGems 2.0 or newer is required to protect against ' \
25
- 'public gem pushes.'
26
- end
27
-
28
17
  # Specify which files should be added to the gem when it is released.
29
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
19
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
@@ -36,7 +25,8 @@ Gem::Specification.new do |spec|
36
25
 
37
26
  spec.add_dependency 'aws-sdk-sqs'
38
27
 
39
- spec.add_development_dependency 'bundler', '~> 1.17.3'
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'rake', '~> 13.0'
40
30
  spec.add_development_dependency 'rspec', '~> 3.0'
41
- spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rubocop', '0.86.0'
42
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neuromancer-indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joergen Dahlke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs
@@ -26,18 +26,32 @@ dependencies:
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 1.17.3
47
+ version: '13.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 1.17.3
54
+ version: '13.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +67,19 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rake
70
+ name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - '='
60
74
  - !ruby/object:Gem::Version
61
- version: '10.0'
75
+ version: 0.86.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - '='
67
81
  - !ruby/object:Gem::Version
68
- version: '10.0'
82
+ version: 0.86.0
69
83
  description: Ruby gem to push data for indexing to the Neuromancer service.
70
84
  email:
71
85
  - joergen.dahlke@infopark.de
@@ -73,30 +87,29 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
90
+ - ".github/workflows/ruby-gems.yml"
91
+ - ".github/workflows/tests.yml"
76
92
  - ".gitignore"
77
93
  - ".rspec"
78
- - ".travis.yml"
94
+ - ".rubocop.yml"
79
95
  - CHANGELOG.md
80
- - Gemfile
81
- - Gemfile.lock
82
96
  - LICENSE
83
97
  - README.md
84
98
  - Rakefile
85
99
  - bin/console
86
100
  - bin/setup
101
+ - gems.locked
102
+ - gems.rb
87
103
  - lib/neuromancer-indexer/rspec.rb
88
104
  - lib/neuromancer/indexer.rb
89
105
  - lib/neuromancer/indexer/client.rb
90
106
  - lib/neuromancer/indexer/configuration.rb
107
+ - lib/neuromancer/indexer/document.rb
91
108
  - lib/neuromancer/indexer/version.rb
92
109
  - neuromancer-indexer.gemspec
93
110
  homepage: https://github.com/jdahlke/neuromancer-indexer
94
111
  licenses: []
95
- metadata:
96
- allowed_push_host: https://rubygems.org
97
- homepage_uri: https://github.com/jdahlke/neuromancer-indexer
98
- source_code_uri: https://github.com/jdahlke/neuromancer-indexer
99
- changelog_uri: https://github.com/jdahlke/neuromancer-indexer/blob/master/CHANGELOG.md
112
+ metadata: {}
100
113
  post_install_message:
101
114
  rdoc_options: []
102
115
  require_paths:
@@ -113,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
126
  version: '0'
114
127
  requirements: []
115
128
  rubyforge_project:
116
- rubygems_version: 2.2.5
129
+ rubygems_version: 2.7.6.2
117
130
  signing_key:
118
131
  specification_version: 4
119
132
  summary: Ruby gem to push data for indexing to the Neuromancer service.
@@ -1,10 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.1.10
5
- - 2.3.8
6
- - 2.5.5
7
- before_install:
8
- - gem install bundler -v 1.17.3
9
- script:
10
- - bundle exec rake spec