harold 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 999bf26c131f015edef47e72ac9f6b231400b54ebf276cad8eb7c88c79645003
4
+ data.tar.gz: 5f12d443f19489932f676ca69f3db7565484c85c90945f0552a733d70cb685b5
5
+ SHA512:
6
+ metadata.gz: e6c3f042e3eab3045f085168a799d4689ef6db09417d3f70d208f36bc09f301ecd6a3a732825c270b323f449ef62138974055961e3cf7701deb05c1418640e34
7
+ data.tar.gz: d4e0edf7a7d67517e436a83d41f77ac104233cf3c9267e7c6f1bd8ea5e6760d48fa74a62d5d7932a6247aaa2fd328d33aa96c89b3a66db32a2854d714f8f3e34
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Lint/AssignmentInCondition:
5
+ Exclude:
6
+ - 'spec/**/*.rb'
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'spec/**/*.rb'
10
+ - '*.gemspec'
11
+ Naming/HeredocDelimiterNaming:
12
+ Enabled: false
13
+ Style/FormatString:
14
+ Enabled: false
15
+ Style/Documentation:
16
+ Enabled: false
17
+ # This is causing breaking changes:
18
+ Style/ExpandPathArguments:
19
+ Enabled: false
20
+ Style/FrozenStringLiteralComment:
21
+ Enabled: false
22
+ Style/GuardClause:
23
+ Enabled: false
24
+ Style/RegexpLiteral:
25
+ Enabled: false
26
+ Style/BlockDelimiters:
27
+ Exclude:
28
+ - 'spec/**/*.rb'
29
+ Metrics/MethodLength:
30
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.7.0
4
+
5
+ services:
6
+ - redis
7
+
8
+ dist: xenial
9
+
10
+ cache: bundler
11
+
12
+ jobs:
13
+ include:
14
+ - stage: Tests
15
+ name: General tests
16
+ script:
17
+ - bundle exec rspec
18
+
19
+ - stage: Tests
20
+ name: Rubocop
21
+ script:
22
+ - bundle exec rubocop
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in harold.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ harold (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.0.2)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rspec (3.9.0)
17
+ rspec-core (~> 3.9.0)
18
+ rspec-expectations (~> 3.9.0)
19
+ rspec-mocks (~> 3.9.0)
20
+ rspec-core (3.9.1)
21
+ rspec-support (~> 3.9.1)
22
+ rspec-expectations (3.9.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-mocks (3.9.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-support (3.9.2)
29
+ rubocop (0.79.0)
30
+ jaro_winkler (~> 1.5.1)
31
+ parallel (~> 1.10)
32
+ parser (>= 2.7.0.1)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ ruby-progressbar (~> 1.7)
35
+ unicode-display_width (>= 1.4.0, < 1.7)
36
+ ruby-progressbar (1.10.1)
37
+ unicode-display_width (1.6.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 2.1)
44
+ harold!
45
+ rspec (~> 3.9)
46
+ rubocop (~> 0.79)
47
+
48
+ BUNDLED WITH
49
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Copyright (c) 2019 WeTransfer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ * The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ * No Harm: The software may not be used by anyone for systems or
15
+ activities that actively and knowingly endanger, harm, or otherwise
16
+ threaten the physical, mental, economic, or general well-being of
17
+ other individuals or groups, in violation of the United Nations
18
+ Universal Declaration of Human Rights
19
+ (https://www.un.org/en/universal-declaration-human-rights/).
20
+
21
+ * Services: If the Software is used to provide a service to others, the
22
+ licensee shall, as a condition of use, require those others not to use
23
+ the service in any way that violates the No Harm clause above.
24
+
25
+ * Enforceability: If any portion or provision of this License shall to
26
+ any extent be declared illegal or unenforceable by a court of
27
+ competent jurisdiction, then the remainder of this License, or the
28
+ application of such portion or provision in circumstances other than
29
+ those as to which it is so declared illegal or unenforceable, shall
30
+ not be affected thereby, and each portion and provision of this
31
+ Agreement shall be valid and enforceable to the fullest extent
32
+ permitted by law.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
+
42
+ This Hippocratic License is an Ethical Source license
43
+ (https://ethicalsource.dev) derived from the MIT License, amended to
44
+ limit the impact of the unethical use of open source software.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # harold [![Build Status](https://travis-ci.com/WeTransfer/harold.svg?token=9FxKF7M1tP265s2qQFFJ&branch=master)](https://travis-ci.com/WeTransfer/harold)
2
+
3
+ A gem which acts like a bookkeeper for who did what to a certain context.
data/harold.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'harold'
6
+ spec.version = '0.0.1'
7
+ spec.authors = ['grdw']
8
+ spec.email = ['gerard@wetransfer.com']
9
+
10
+ spec.summary = 'Helpers for collaborative environments'
11
+ spec.description = <<~EOS
12
+ Library that contains helpers for collaborative environments
13
+ EOS
14
+ spec.homepage = 'https://github.com/wetransfer/harold'
15
+ spec.license = 'GPL-3.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/wetransfer/harold'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/wetransfer/harold/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
23
+ # into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.1'
34
+ spec.add_development_dependency 'rspec', '~> 3.9'
35
+ spec.add_development_dependency 'rubocop', '~> 0.79'
36
+ end
data/lib/harold.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'operation'
2
+ require_relative 'strategies/cancel'
data/lib/operation.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Harold
2
+ class Operation
3
+ VALID_TYPES = %i[add update delete].freeze
4
+ attr_reader :id, :type, :payload
5
+
6
+ def initialize(id, type, payload = {})
7
+ unless VALID_TYPES.include?(type)
8
+ raise ArgumentError,
9
+ "#{type} is not a valid type"
10
+ end
11
+
12
+ @id = id
13
+ @type = type
14
+ @payload = payload
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ module Harold
2
+ module Strategies
3
+ class Cancel
4
+ def self.call(operations)
5
+ new(operations).cancel
6
+ end
7
+
8
+ private_class_method :new
9
+
10
+ def initialize(operations)
11
+ @operations = operations
12
+ @useful_items = useful_items(operations)
13
+ end
14
+
15
+ def cancel
16
+ @operations.select do |operation|
17
+ @useful_items.include?(operation.id)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ # This lists the operation id's which are considered useful.
24
+ # The result of this method are all the id's of operations which
25
+ # have been added 'or' updated. All items which are added/updated
26
+ # 'and' afterwards deleted will be non-present in this list.
27
+ def useful_items(operations)
28
+ operations.each_with_object(Set.new) do |op, items|
29
+ if op.type == :delete && items.include?(op.id)
30
+ items.delete(op.id)
31
+ else
32
+ items.add(op.id)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - grdw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.79'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.79'
55
+ description: 'Library that contains helpers for collaborative environments
56
+
57
+ '
58
+ email:
59
+ - gerard@wetransfer.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rubocop.yml"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE
70
+ - README.md
71
+ - harold.gemspec
72
+ - lib/harold.rb
73
+ - lib/operation.rb
74
+ - lib/strategies/cancel.rb
75
+ homepage: https://github.com/wetransfer/harold
76
+ licenses:
77
+ - GPL-3.0
78
+ metadata:
79
+ homepage_uri: https://github.com/wetransfer/harold
80
+ source_code_uri: https://github.com/wetransfer/harold
81
+ changelog_uri: https://github.com/wetransfer/harold/CHANGELOG.md
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.1.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Helpers for collaborative environments
101
+ test_files: []