dmx-storage 0.0.1.pre.alpha21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.semaphore/rubygems.yml +31 -0
- data/.semaphore/semaphore.yml +28 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/storage.rb +5 -0
- data/lib/storage/algolia/actions/all.rb +32 -0
- data/lib/storage/algolia/actions/create.rb +41 -0
- data/lib/storage/algolia/actions/delete.rb +34 -0
- data/lib/storage/algolia/actions/get.rb +31 -0
- data/lib/storage/algolia/actions/update.rb +45 -0
- data/lib/storage/algolia/algolia.rb +48 -0
- data/lib/storage/algolia/base.rb +49 -0
- data/lib/storage/algolia/index/clear.rb +21 -0
- data/lib/storage/algolia/normalize_id.rb +26 -0
- data/lib/storage/application_service.rb +7 -0
- data/lib/storage/version.rb +5 -0
- data/storage.gemspec +40 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 72436ca4906c0d112793ea6e6ddc2c5e63b1a97c1636c72bb55f1f46a9749e90
|
4
|
+
data.tar.gz: c4d83093d6ff0307a42ff31637f86c5bf38218ba7e566617cebea9a018d0b966
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f45fccf69f314287532193319eebdf9f5361c52237d6e1f06963ac73b00e17318ab76d9d75ad8b6408a0fd691d8e297d5ffd5e852bdd03f9b4f01e8af670454
|
7
|
+
data.tar.gz: eaa57c6eb5048f561da6b88cbb2fe22607208297080ee3be0cef18274e8f1295ec1aee48beb6e3e43120c5837e32a46d4213d4a06f05dd463161c80cdfb22d99
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# .semaphore/production-deploy.yml
|
2
|
+
version: v1.0
|
3
|
+
name: Deploy to rubygems
|
4
|
+
agent:
|
5
|
+
machine:
|
6
|
+
type: e1-standard-2
|
7
|
+
os_image: ubuntu1804
|
8
|
+
blocks:
|
9
|
+
- name: Deploy
|
10
|
+
task:
|
11
|
+
secrets:
|
12
|
+
- name: dmx-gems
|
13
|
+
prologue:
|
14
|
+
commands:
|
15
|
+
- touch ~/.gem/credentials
|
16
|
+
- |
|
17
|
+
echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
|
18
|
+
- chmod 0600 ~/.gem/credentials
|
19
|
+
- sem-version ruby 2.6.1
|
20
|
+
- checkout
|
21
|
+
- cache restore
|
22
|
+
- bundle install
|
23
|
+
jobs:
|
24
|
+
- name: 'Build and deploy'
|
25
|
+
commands:
|
26
|
+
- export GEM_VERSION=0.0.1.pre.alpha$SEMAPHORE_WORKFLOW_NUMBER
|
27
|
+
- export GEM_NAME=dmx-storage-$GEM_VERSION.gem
|
28
|
+
- cat ~/.gem/credentials
|
29
|
+
- gem build storage.gemspec
|
30
|
+
- gem push $GEM_NAME
|
31
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
version: v1.0
|
2
|
+
name: First pipeline
|
3
|
+
agent:
|
4
|
+
machine:
|
5
|
+
type: e1-standard-2
|
6
|
+
os_image: ubuntu1804
|
7
|
+
blocks:
|
8
|
+
- name: Unit tests
|
9
|
+
task:
|
10
|
+
secrets:
|
11
|
+
- name: dmx-gems
|
12
|
+
prologue:
|
13
|
+
commands:
|
14
|
+
- sem-version ruby 2.6.1
|
15
|
+
- checkout
|
16
|
+
- cache restore
|
17
|
+
- bundle install
|
18
|
+
- cache store
|
19
|
+
jobs:
|
20
|
+
- name: specs
|
21
|
+
commands:
|
22
|
+
- bundle exec rspec
|
23
|
+
- echo $SEMAPHORE_WORKFLOW_NUMBER
|
24
|
+
promotions:
|
25
|
+
- name: Deploys to rubygems
|
26
|
+
pipeline_file: rubygems.yml
|
27
|
+
auto_promote:
|
28
|
+
when: "result = 'passed' and branch = 'master'"
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at 44549254+cctvuser@users.noreply.github.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dmx-storage (0.0.1)
|
5
|
+
activesupport (~> 6.0.0)
|
6
|
+
algoliasearch (~> 1.27.1)
|
7
|
+
dotenv (~> 2.7.5)
|
8
|
+
hashugar (~> 1.0.1)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (6.0.0)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (>= 0.7, < 2)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
19
|
+
addressable (2.7.0)
|
20
|
+
public_suffix (>= 2.0.2, < 5.0)
|
21
|
+
algoliasearch (1.27.1)
|
22
|
+
httpclient (~> 2.8, >= 2.8.3)
|
23
|
+
json (>= 1.5.1)
|
24
|
+
byebug (11.0.1)
|
25
|
+
concurrent-ruby (1.1.5)
|
26
|
+
crack (0.4.3)
|
27
|
+
safe_yaml (~> 1.0.0)
|
28
|
+
diff-lcs (1.3)
|
29
|
+
dotenv (2.7.5)
|
30
|
+
hashdiff (1.0.0)
|
31
|
+
hashugar (1.0.1)
|
32
|
+
httpclient (2.8.3)
|
33
|
+
i18n (1.7.0)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
json (2.2.0)
|
36
|
+
minitest (5.12.2)
|
37
|
+
public_suffix (4.0.1)
|
38
|
+
rake (10.5.0)
|
39
|
+
rspec (3.9.0)
|
40
|
+
rspec-core (~> 3.9.0)
|
41
|
+
rspec-expectations (~> 3.9.0)
|
42
|
+
rspec-mocks (~> 3.9.0)
|
43
|
+
rspec-core (3.9.0)
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-expectations (3.9.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.9.0)
|
48
|
+
rspec-mocks (3.9.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.9.0)
|
51
|
+
rspec-support (3.9.0)
|
52
|
+
safe_yaml (1.0.5)
|
53
|
+
thread_safe (0.3.6)
|
54
|
+
tzinfo (1.2.5)
|
55
|
+
thread_safe (~> 0.1)
|
56
|
+
webmock (3.7.6)
|
57
|
+
addressable (>= 2.3.6)
|
58
|
+
crack (>= 0.3.2)
|
59
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
60
|
+
zeitwerk (2.2.0)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
bundler (~> 2.0)
|
67
|
+
byebug (~> 11.0.1)
|
68
|
+
dmx-storage!
|
69
|
+
rake (~> 10.0)
|
70
|
+
rspec (~> 3.0)
|
71
|
+
webmock (~> 3.7.6)
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 CCTV
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Storage
|
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/storage`. 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 'storage'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install storage
|
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]/storage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Storage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/storage/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "storage"
|
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
data/lib/storage.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/algolia/base'
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
module Algolia
|
7
|
+
module Actions
|
8
|
+
class All < ::Storage::Algolia::Base
|
9
|
+
attr_reader :model_name, :cursor
|
10
|
+
|
11
|
+
def initialize(model_name:, cursor: nil)
|
12
|
+
@model_name = model_name
|
13
|
+
@cursor = cursor
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
normalize query.dig('hits')
|
18
|
+
end
|
19
|
+
|
20
|
+
def meta
|
21
|
+
query.except!('hits').to_hashugar
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def query
|
27
|
+
@query ||= index.browse({ cursor: cursor })
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/algolia/base'
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
module Algolia
|
7
|
+
module Actions
|
8
|
+
class Create < ::Storage::Algolia::Base
|
9
|
+
attr_reader :model_name, :params
|
10
|
+
|
11
|
+
def initialize(model_name:, params:)
|
12
|
+
@model_name = model_name
|
13
|
+
@params = params
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
raise Exception unless task.dig('objectID')
|
18
|
+
|
19
|
+
normalize params.to_hash.merge(
|
20
|
+
objectID: task.dig('objectID'),
|
21
|
+
updatedAt: task.dig('updatedAt')
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def task
|
28
|
+
@task ||= index.save_object(payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
def payload
|
32
|
+
{ objectID: SecureRandom.uuid }.merge(params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def uuid
|
36
|
+
@uuid ||= ::SecureRandom.uuid
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/algolia/base'
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
module Algolia
|
7
|
+
module Actions
|
8
|
+
class Delete < ::Storage::Algolia::Base
|
9
|
+
MAX_RETRIES = 3
|
10
|
+
|
11
|
+
attr_reader :model_name, :id, :retries
|
12
|
+
|
13
|
+
def initialize(model_name:, id:)
|
14
|
+
@model_name = model_name
|
15
|
+
@id = id
|
16
|
+
@retries = 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def process
|
20
|
+
index.delete_object(original_object.id)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def original_object
|
26
|
+
@original_object ||= ::Storage::Algolia::Actions::Get.process(
|
27
|
+
model_name: model_name,
|
28
|
+
id: id
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/algolia/base'
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
module Algolia
|
7
|
+
module Actions
|
8
|
+
class Get < ::Storage::Algolia::Base
|
9
|
+
MAX_RETRIES = 3
|
10
|
+
|
11
|
+
attr_reader :model_name, :id, :retries
|
12
|
+
|
13
|
+
def initialize(model_name:, id:)
|
14
|
+
@model_name = model_name
|
15
|
+
@id = id
|
16
|
+
@retries = 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def process
|
20
|
+
@retries += 1
|
21
|
+
normalize index.get_object(id).deep_transform_keys(&:to_sym)
|
22
|
+
rescue => e
|
23
|
+
pp "Retrying (#{@retries}/#{MAX_RETRIES})..."
|
24
|
+
sleep 2
|
25
|
+
retry if @retries <= MAX_RETRIES
|
26
|
+
raise Exception
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/algolia/base'
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
module Algolia
|
7
|
+
module Actions
|
8
|
+
class Update < ::Storage::Algolia::Base
|
9
|
+
attr_reader :model_name, :params, :id, :retries
|
10
|
+
|
11
|
+
def initialize(model_name:, params:, id:)
|
12
|
+
@model_name = model_name
|
13
|
+
@params = params
|
14
|
+
@id = id
|
15
|
+
@retries = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def process
|
19
|
+
raise Exception unless task.dig('objectID')
|
20
|
+
|
21
|
+
normalize original_object.to_hash.merge(
|
22
|
+
{
|
23
|
+
objectID: task.dig('objectID'),
|
24
|
+
updatedAt: task.dig('updatedAt')
|
25
|
+
},
|
26
|
+
params
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def original_object
|
33
|
+
@original_object ||= ::Storage::Algolia::Actions::Get.process(
|
34
|
+
model_name: model_name,
|
35
|
+
id: id
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def task
|
40
|
+
@task ||= index.partial_update_object(params, id)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storage
|
4
|
+
module Algolia
|
5
|
+
def self.all(model_name:, cursor: nil)
|
6
|
+
::Storage::Algolia::Actions::All.new(
|
7
|
+
model_name: model_name,
|
8
|
+
cursor: cursor
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get(model_name:, id:)
|
13
|
+
::Storage::Algolia::Actions::Get.process(
|
14
|
+
model_name: model_name,
|
15
|
+
id: id
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create(model_name:, params:)
|
20
|
+
::Storage::Algolia::Actions::Create.process(
|
21
|
+
model_name: model_name,
|
22
|
+
params: params
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.update(model_name:, params:, id:)
|
27
|
+
::Storage::Algolia::Actions::Update.process(
|
28
|
+
model_name: model_name,
|
29
|
+
params: params,
|
30
|
+
id: id
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.delete(model_name:, id:)
|
35
|
+
::Storage::Algolia::Actions::Delete.process(
|
36
|
+
model_name: model_name,
|
37
|
+
id: id
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.clear(model_name:)
|
42
|
+
::Storage::Algolia::Index::Clear.process(
|
43
|
+
model_name: model_name
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/application_service'
|
4
|
+
require 'algoliasearch'
|
5
|
+
require 'hashugar'
|
6
|
+
require 'active_support/core_ext/hash/except'
|
7
|
+
require 'active_support/core_ext/hash/keys'
|
8
|
+
require 'dotenv/load'
|
9
|
+
::Dotenv.load
|
10
|
+
|
11
|
+
module Storage
|
12
|
+
module Algolia
|
13
|
+
class Base < ::ApplicationService
|
14
|
+
private
|
15
|
+
|
16
|
+
def index
|
17
|
+
@index ||= begin
|
18
|
+
::Algolia.init(
|
19
|
+
application_id: algolia_application_id,
|
20
|
+
api_key: algolia_admin_api_key
|
21
|
+
)
|
22
|
+
::Algolia::Index.new(model_name.to_s)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def normalize(data)
|
27
|
+
::Algolia::NormalizeId.process(data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def params
|
31
|
+
NoMethodError
|
32
|
+
end
|
33
|
+
|
34
|
+
def model_name
|
35
|
+
NoMethodError
|
36
|
+
end
|
37
|
+
|
38
|
+
def algolia_application_id
|
39
|
+
ENV['ALGOLIA_APPLICATION_ID'] ||
|
40
|
+
raise(Exception, 'Missing algolia application id')
|
41
|
+
end
|
42
|
+
|
43
|
+
def algolia_admin_api_key
|
44
|
+
ENV['ALGOLIA_ADMIN_API_KEY'] ||
|
45
|
+
raise(Exception, 'Missing algolia admin api key')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/algolia/base'
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
module Algolia
|
7
|
+
module Index
|
8
|
+
class Clear < ::Storage::Algolia::Base
|
9
|
+
attr_reader :model_name
|
10
|
+
|
11
|
+
def initialize(model_name:)
|
12
|
+
@model_name = model_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
index.clear
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/storage/application_service'
|
4
|
+
|
5
|
+
module Algolia
|
6
|
+
class NormalizeId < ::ApplicationService
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def process
|
14
|
+
data.kind_of?(Array) ?
|
15
|
+
data.map { |node| objectid_to_id(node) }.to_hashugar :
|
16
|
+
objectid_to_id(data)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def objectid_to_id(node)
|
22
|
+
node[:id] = node.delete(:objectID)
|
23
|
+
node.to_hashugar
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/storage.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "storage/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'dmx-storage'
|
7
|
+
spec.version = ENV['GEM_VERSION'] || Storage::VERSION
|
8
|
+
spec.authors = ["CCTV"]
|
9
|
+
spec.email = ["ben@dee.mx"]
|
10
|
+
spec.summary = %q{Write a short summary, because RubyGems requires one.}
|
11
|
+
spec.description = %q{Write a longer description or delete this line.}
|
12
|
+
spec.homepage = 'http://github.com'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'http://github.com'
|
18
|
+
spec.metadata['changelog_uri'] = 'http://github.com'
|
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
|
+
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'hashugar', '~> 1.0.1'
|
31
|
+
spec.add_dependency 'dotenv', '~> 2.7.5'
|
32
|
+
spec.add_dependency 'algoliasearch', '~> 1.27.1'
|
33
|
+
spec.add_dependency 'activesupport', '~> 6.0.0'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'webmock', '~> 3.7.6'
|
39
|
+
spec.add_development_dependency 'byebug', '~> 11.0.1'
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dmx-storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre.alpha21
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CCTV
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashugar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: algoliasearch
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.27.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.27.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 6.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.7.6
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.7.6
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 11.0.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 11.0.1
|
139
|
+
description: Write a longer description or delete this line.
|
140
|
+
email:
|
141
|
+
- ben@dee.mx
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".semaphore/rubygems.yml"
|
149
|
+
- ".semaphore/semaphore.yml"
|
150
|
+
- ".travis.yml"
|
151
|
+
- CODE_OF_CONDUCT.md
|
152
|
+
- Gemfile
|
153
|
+
- Gemfile.lock
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- bin/console
|
158
|
+
- bin/setup
|
159
|
+
- lib/storage.rb
|
160
|
+
- lib/storage/algolia/actions/all.rb
|
161
|
+
- lib/storage/algolia/actions/create.rb
|
162
|
+
- lib/storage/algolia/actions/delete.rb
|
163
|
+
- lib/storage/algolia/actions/get.rb
|
164
|
+
- lib/storage/algolia/actions/update.rb
|
165
|
+
- lib/storage/algolia/algolia.rb
|
166
|
+
- lib/storage/algolia/base.rb
|
167
|
+
- lib/storage/algolia/index/clear.rb
|
168
|
+
- lib/storage/algolia/normalize_id.rb
|
169
|
+
- lib/storage/application_service.rb
|
170
|
+
- lib/storage/version.rb
|
171
|
+
- storage.gemspec
|
172
|
+
homepage: http://github.com
|
173
|
+
licenses:
|
174
|
+
- MIT
|
175
|
+
metadata:
|
176
|
+
allowed_push_host: https://rubygems.org
|
177
|
+
homepage_uri: http://github.com
|
178
|
+
source_code_uri: http://github.com
|
179
|
+
changelog_uri: http://github.com
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">"
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: 1.3.1
|
194
|
+
requirements: []
|
195
|
+
rubygems_version: 3.0.3
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Write a short summary, because RubyGems requires one.
|
199
|
+
test_files: []
|