qfill 0.0.3 → 0.1.1

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +8 -0
  3. data/.github/workflows/style.yml +37 -0
  4. data/.github/workflows/test.yml +55 -0
  5. data/.rspec +3 -2
  6. data/.rubocop.yml +26 -0
  7. data/.rubocop_todo.yml +163 -0
  8. data/.simplecov +6 -0
  9. data/CODE_OF_CONDUCT.md +133 -0
  10. data/Gemfile +31 -0
  11. data/Guardfile +12 -0
  12. data/{LICENSE.txt → LICENSE} +1 -1
  13. data/README.md +2 -2
  14. data/Rakefile +24 -1
  15. data/lib/qfill/errors/invalid_index.rb +8 -0
  16. data/lib/qfill/filter.rb +5 -3
  17. data/lib/qfill/list.rb +4 -2
  18. data/lib/qfill/list_set.rb +17 -7
  19. data/lib/qfill/manager.rb +90 -61
  20. data/lib/qfill/origin.rb +4 -3
  21. data/lib/qfill/popper.rb +31 -26
  22. data/lib/qfill/pusher.rb +34 -23
  23. data/lib/qfill/result.rb +78 -40
  24. data/lib/qfill/strategy/base.rb +65 -0
  25. data/lib/qfill/strategy/drain_to_empty.rb +73 -0
  26. data/lib/qfill/strategy/drain_to_limit.rb +46 -0
  27. data/lib/qfill/strategy/sample.rb +42 -0
  28. data/lib/qfill/strategy/time_slice.rb +105 -0
  29. data/lib/qfill/strategy.rb +13 -0
  30. data/lib/qfill/version.rb +3 -1
  31. data/lib/qfill.rb +13 -10
  32. data/maintenance-branch +1 -0
  33. data/qfill.gemspec +15 -13
  34. data/spec/qfill/filter_spec.rb +35 -26
  35. data/spec/qfill/list_set_spec.rb +28 -23
  36. data/spec/qfill/list_spec.rb +35 -27
  37. data/spec/qfill/manager_spec.rb +715 -284
  38. data/spec/qfill/origin_spec.rb +45 -35
  39. data/spec/qfill/popper_spec.rb +36 -30
  40. data/spec/qfill/pusher_spec.rb +32 -26
  41. data/spec/qfill/result_spec.rb +49 -38
  42. data/spec/qfill_spec.rb +6 -5
  43. data/spec/spec_helper.rb +11 -37
  44. data/spec/support/helper.rb +13 -0
  45. data/spec/support/random_object.rb +30 -0
  46. metadata +52 -23
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ebf168a7298dded7f0c9f3eb4e4edd7fd6f6150465a857343c2433eae5861364
4
+ data.tar.gz: 8917c3a87fdb98aea36a483008d26e46099bae22ce904b6802df9e310c6053c5
5
+ SHA512:
6
+ metadata.gz: aa7d5e8882e07947969161d2da89dab24d5e2549ea5138b95fef4bf90ffa82b2eb451133281c1de72c328a903850e6434a701d753b55e7c9aae690f5709e6b50
7
+ data.tar.gz: df6957d37df1670ad0362c333b60540ed8242b2f8b3db7a84fcf2219cdda5012a5698cbd2cad51054d8cb4a1241b208db46d406df4c8caae68016b78a2980a20
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "04:28"
8
+ open-pull-requests-limit: 10
@@ -0,0 +1,37 @@
1
+ name: Code Style Checks
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'main'
7
+ - 'master'
8
+ - '*-maintenance'
9
+ - '*-dev'
10
+ tags:
11
+ - '!*' # Do not execute on tags
12
+ pull_request:
13
+ branches:
14
+ - '*'
15
+
16
+ jobs:
17
+ rubocop:
18
+ name: Rubocop
19
+ if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')"
20
+ strategy:
21
+ fail-fast: false
22
+ matrix:
23
+ ruby:
24
+ - 2.7
25
+ runs-on: ubuntu-20.04
26
+ steps:
27
+ - name: Checkout
28
+ uses: actions/checkout@v2
29
+ - name: Setup Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+ bundler-cache: true
34
+ - name: Install dependencies
35
+ run: bundle install --jobs 3 --retry 3
36
+ - name: Run Rubocop
37
+ run: bundle exec rubocop -DESP
@@ -0,0 +1,55 @@
1
+ name: Unit Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'main'
7
+ - 'master'
8
+ - '*-maintenance'
9
+ - '*-dev'
10
+ tags:
11
+ - '!*' # Do not execute on tags
12
+ pull_request:
13
+ branches:
14
+ - '*'
15
+
16
+ jobs:
17
+ test:
18
+ name: Specs - Ruby ${{ matrix.ruby }} ${{ matrix.name_extra || '' }}
19
+ if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')"
20
+ strategy:
21
+ fail-fast: false
22
+ matrix:
23
+ ruby:
24
+ - 3.0.0
25
+ - 2.7
26
+ - 2.6
27
+ - 2.5
28
+ - 2.4
29
+ runs-on: ubuntu-20.04
30
+ continue-on-error: ${{ matrix.allow_failure || endsWith(matrix.ruby, 'head') }}
31
+ steps:
32
+ - uses: amancevice/setup-code-climate@v0
33
+ name: CodeClimate Install
34
+ if: matrix.ruby == '2.7' && github.event_name != 'pull_request'
35
+ with:
36
+ cc_test_reporter_id: ${{ secrets.CC_TEST_REPORTER_ID }}
37
+ - uses: actions/checkout@v2
38
+ - name: Setup Ruby
39
+ uses: ruby/setup-ruby@v1
40
+ with:
41
+ bundler: ${{ matrix.bundler || 2 }}
42
+ bundler-cache: true
43
+ ruby-version: ${{ matrix.ruby }}
44
+ - name: Install dependencies
45
+ run: bundle install --jobs 3 --retry 3 --binstubs --standalone
46
+ - name: CodeClimate Pre-build Notification
47
+ run: cc-test-reporter before-build
48
+ if: matrix.ruby == '2.7' && github.event_name != 'pull_request'
49
+ continue-on-error: ${{ matrix.allow_failures != 'false' }}
50
+ - name: Run tests
51
+ run: bundle exec rake test
52
+ - name: CodeClimate Post-build Notification
53
+ run: cc-test-reporter after-build
54
+ if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always()
55
+ continue-on-error: ${{ matrix.allow_failures != 'false' }}
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
- --color
2
- --format progress
1
+ --require spec_helper
2
+ --format=documentation
3
+ --colour
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require:
4
+ - 'rubocop-md'
5
+ - 'rubocop-packaging'
6
+ - 'rubocop-performance'
7
+ - 'rubocop-rake'
8
+ - 'rubocop-rspec'
9
+
10
+ AllCops:
11
+ NewCops: enable
12
+ DisplayCopNames: true # Display the name of the failing cops
13
+ Exclude:
14
+ - 'gemfiles/vendor/**/*'
15
+ - 'vendor/**/*'
16
+
17
+ Metrics/BlockLength:
18
+ IgnoredMethods:
19
+ - context
20
+ - describe
21
+ - it
22
+ - shared_context
23
+ - shared_examples
24
+ - shared_examples_for
25
+ - namespace
26
+ - draw
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,163 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-04-22 19:38:54 UTC using RuboCop version 1.13.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'qfill.gemspec'
15
+
16
+ # Offense count: 3
17
+ Lint/BinaryOperatorWithIdenticalOperands:
18
+ Exclude:
19
+ - 'spec/qfill/filter_spec.rb'
20
+
21
+ # Offense count: 1
22
+ # Configuration parameters: AllowComments, AllowEmptyLambdas.
23
+ Lint/EmptyBlock:
24
+ Exclude:
25
+ - 'spec/qfill/manager_spec.rb'
26
+
27
+ # Offense count: 3
28
+ Lint/UselessAssignment:
29
+ Exclude:
30
+ - '**/*.md'
31
+ - '**/*.markdown'
32
+ - 'lib/qfill/list_set.rb'
33
+ - 'lib/qfill/popper.rb'
34
+ - 'spec/qfill/filter_spec.rb'
35
+
36
+ # Offense count: 14
37
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
38
+ Metrics/AbcSize:
39
+ Max: 39
40
+
41
+ # Offense count: 1
42
+ # Configuration parameters: CountComments, CountAsOne.
43
+ Metrics/ClassLength:
44
+ Max: 106
45
+
46
+ # Offense count: 1
47
+ # Configuration parameters: IgnoredMethods.
48
+ Metrics/CyclomaticComplexity:
49
+ Max: 8
50
+
51
+ # Offense count: 8
52
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
53
+ Metrics/MethodLength:
54
+ Max: 20
55
+
56
+ # Offense count: 1
57
+ # Configuration parameters: IgnoredMethods.
58
+ Metrics/PerceivedComplexity:
59
+ Max: 9
60
+
61
+ # Offense count: 1
62
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
63
+ # AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
64
+ Naming/MethodParameterName:
65
+ Exclude:
66
+ - 'lib/qfill/popper.rb'
67
+
68
+ # Offense count: 3
69
+ # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
70
+ # NamePrefix: is_, has_, have_
71
+ # ForbiddenPrefixes: is_, has_, have_
72
+ # AllowedMethods: is_a?
73
+ # MethodDefinitionMacros: define_method, define_singleton_method
74
+ Naming/PredicateName:
75
+ Exclude:
76
+ - 'spec/**/*'
77
+ - 'lib/qfill/manager.rb'
78
+ - 'lib/qfill/origin.rb'
79
+ - 'lib/qfill/result.rb'
80
+
81
+ # Offense count: 1
82
+ Packaging/GemspecGit:
83
+ Exclude:
84
+ - 'qfill.gemspec'
85
+
86
+ # Offense count: 22
87
+ # Configuration parameters: Prefixes.
88
+ # Prefixes: when, with, without
89
+ RSpec/ContextWording:
90
+ Exclude:
91
+ - 'spec/qfill/manager_spec.rb'
92
+
93
+ # Offense count: 1
94
+ RSpec/EmptyExampleGroup:
95
+ Exclude:
96
+ - 'spec/qfill/manager_spec.rb'
97
+
98
+ # Offense count: 45
99
+ # Configuration parameters: AssignmentOnly.
100
+ RSpec/InstanceVariable:
101
+ Exclude:
102
+ - 'spec/qfill/filter_spec.rb'
103
+ - 'spec/qfill/list_set_spec.rb'
104
+ - 'spec/qfill/list_spec.rb'
105
+ - 'spec/qfill/origin_spec.rb'
106
+ - 'spec/qfill/popper_spec.rb'
107
+ - 'spec/qfill/pusher_spec.rb'
108
+ - 'spec/qfill/result_spec.rb'
109
+
110
+ # Offense count: 7
111
+ RSpec/MultipleExpectations:
112
+ Max: 2
113
+
114
+ # Offense count: 34
115
+ RSpec/NestedGroups:
116
+ Max: 6
117
+
118
+ # Offense count: 1
119
+ Rake/Desc:
120
+ Exclude:
121
+ - 'Rakefile'
122
+
123
+ # Offense count: 14
124
+ # Configuration parameters: AllowedConstants.
125
+ Style/Documentation:
126
+ Exclude:
127
+ - '**/*.md'
128
+ - '**/*.markdown'
129
+ - 'lib/qfill/filter.rb'
130
+ - 'lib/qfill/list.rb'
131
+ - 'lib/qfill/list_set.rb'
132
+ - 'lib/qfill/manager.rb'
133
+ - 'lib/qfill/origin.rb'
134
+ - 'lib/qfill/popper.rb'
135
+ - 'lib/qfill/pusher.rb'
136
+ - 'lib/qfill/result.rb'
137
+ - 'lib/qfill/strategy/base.rb'
138
+ - 'lib/qfill/strategy/drain_to_empty.rb'
139
+ - 'lib/qfill/strategy/drain_to_limit.rb'
140
+ - 'lib/qfill/strategy/sample.rb'
141
+ - 'spec/support/helper.rb'
142
+ - 'spec/support/random_object.rb'
143
+
144
+ # Offense count: 2
145
+ # Configuration parameters: MinBodyLength.
146
+ Style/GuardClause:
147
+ Exclude:
148
+ - 'lib/qfill/pusher.rb'
149
+ - 'lib/qfill/result.rb'
150
+
151
+ # Offense count: 1
152
+ # Cop supports --auto-correct.
153
+ Style/IfUnlessModifier:
154
+ Exclude:
155
+ - 'lib/qfill/manager.rb'
156
+
157
+ # Offense count: 24
158
+ # Cop supports --auto-correct.
159
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
160
+ # URISchemes: http, https
161
+ # IgnoredPatterns: (?-mix:^\#)
162
+ Layout/LineLength:
163
+ Max: 274
data/.simplecov ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start do
4
+ add_filter '/spec/'
5
+ add_filter '/vendor/bundle/'
6
+ end
@@ -0,0 +1,133 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, religion, or sexual identity
11
+ and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the
27
+ overall community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or
32
+ advances of any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email
36
+ address, without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ [INSERT CONTACT METHOD].
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series
87
+ of actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or
94
+ permanent ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within
114
+ the community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.0, available at
120
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
127
+ at [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
data/Gemfile CHANGED
@@ -1,4 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in qfill.gemspec
4
6
  gemspec
7
+
8
+ ruby_version = Gem::Version.new(RUBY_VERSION)
9
+
10
+ gem 'yard', '~> 0.9.24', require: false
11
+
12
+ ### deps for rdoc.info
13
+ group :documentation do
14
+ gem 'github-markup', platform: :mri
15
+ gem 'redcarpet', platform: :mri
16
+ end
17
+
18
+ group :development, :test do
19
+ if ruby_version >= Gem::Version.new('2.4')
20
+ # No need to run byebug on earlier versions
21
+ gem 'byebug', platform: :mri
22
+ end
23
+
24
+ if ruby_version >= Gem::Version.new('2.7')
25
+ # No need to run rubocop or simplecov on earlier versions
26
+ gem 'rubocop', '~> 1.9', platform: :mri
27
+ gem 'rubocop-md', platform: :mri
28
+ gem 'rubocop-packaging', platform: :mri
29
+ gem 'rubocop-performance', platform: :mri
30
+ gem 'rubocop-rake', platform: :mri
31
+ gem 'rubocop-rspec', platform: :mri
32
+
33
+ gem 'simplecov', '~> 0.21', platform: :mri
34
+ end
35
+ end
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard 'rspec', version: 2 do
4
+ watch(%r{^spec/.+_spec\.rb$})
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
+ watch('spec/spec_helper.rb') { 'spec' }
7
+ end
8
+
9
+ guard 'bundler' do
10
+ watch('Gemfile')
11
+ watch(/^.+\.gemspec/)
12
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Peter Boling
1
+ Copyright (c) 2013-2021 Peter Boling
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Qfill - Advanced Queue Tranformations
1
+ # Qfill - Advanced Queue Transformations
2
2
 
3
3
  This gem takes a dynamic number of queues (arrays) of things, and manages the transformation into a new set of queues,
4
4
  according to a dynamic set of guidelines.
@@ -23,7 +23,7 @@ There will be a dynamic number of origination queues each containing a set of sn
23
23
  some matching criteria.
24
24
  There is a Popper which is called to pop the next object from the next origination queue.
25
25
  There is a Filter which is optionally called to validate any object that is popped from the origin.
26
- Origin keeps popping until an object is validated for as a result-worthy object.
26
+ Origin keeps popping until an object is validated as a result-worthy object.
27
27
 
28
28
  Example:
29
29
 
data/Rakefile CHANGED
@@ -1 +1,24 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ rescue LoadError
9
+ task :spec do
10
+ warn 'RSpec is disabled'
11
+ end
12
+ end
13
+ task test: :spec
14
+
15
+ begin
16
+ require 'rubocop/rake_task'
17
+ RuboCop::RakeTask.new
18
+ rescue LoadError
19
+ task :rubocop do
20
+ warn 'RuboCop is disabled'
21
+ end
22
+ end
23
+
24
+ task default: [:test]
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Qfill
4
+ module Errors
5
+ class InvalidIndex < StandardError
6
+ end
7
+ end
8
+ end
data/lib/qfill/filter.rb CHANGED
@@ -1,5 +1,7 @@
1
- #filter1 = Qfill::Filter.new( -> (object, stuff, stank) { object.is_awesome_enough_to_be_in_results?(stuff, stank) }, stuff, stank)
2
- #filter2 = Qfill::Filter.new( -> (object, rank, bank) { object.is_awesome_enough_to_be_in_results?(rank, bank) }, rank, bank)
1
+ # frozen_string_literal: true
2
+
3
+ # filter1 = Qfill::Filter.new( -> (object, stuff, stank) { object.is_awesome_enough_to_be_in_results?(stuff, stank) }, stuff, stank)
4
+ # filter2 = Qfill::Filter.new( -> (object, rank, bank) { object.is_awesome_enough_to_be_in_results?(rank, bank) }, rank, bank)
3
5
  #
4
6
  # Filters are destructive. If an item is filtered from a Result list it is lost, since it has already been popped off the origin list, and won't be coming back
5
7
  module Qfill
@@ -12,7 +14,7 @@ module Qfill
12
14
  end
13
15
 
14
16
  def run(*args)
15
- self.processor.call(*args, *self.processor_arguments)
17
+ processor.call(*args, *processor_arguments)
16
18
  end
17
19
  end
18
20
  end
data/lib/qfill/list.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the base queue class for Origin queues and Result queues.
2
4
  #
3
- #Qfill::List.new(:name => "High List",
5
+ # Qfill::List.new(:name => "High List",
4
6
  # :elements => [Thing1, Thing3],
5
7
  # :filter => filter1),
6
8
  module Qfill
@@ -9,10 +11,10 @@ module Qfill
9
11
 
10
12
  def initialize(options = {})
11
13
  raise ArgumentError, "Missing required option :name for #{self.class}.new()" unless options && options[:name]
14
+
12
15
  @name = options[:name]
13
16
  @elements = options[:elements] || []
14
17
  @filter = options[:filter]
15
18
  end
16
-
17
19
  end
18
20
  end
@@ -1,29 +1,39 @@
1
- #popper = Qfill::ListSet.new(
1
+ # frozen_string_literal: true
2
+
3
+ # This is the base queues class for Popper queues and Pusher queues.
4
+ #
5
+ # popper = Qfill::ListSet.new(
2
6
  # Qfill::List.new( :name => "High List",
3
7
  # :elements => [Thing1, Thing3],
4
8
  # :filter => filter1 ) )
5
9
  module Qfill
6
10
  class ListSet
7
-
8
11
  attr_accessor :queues, :current_index
9
12
 
10
13
  def initialize(*args)
11
- raise ArgumentError, "Missing required arguments for #{self.class}.new(queues)" unless args.length > 0
14
+ raise ArgumentError, "Missing required arguments for #{self.class}.new(queues)" unless args.length.positive?
15
+
12
16
  @queues = args
13
17
  @current_index = 0
14
18
  end
15
19
 
16
20
  def [](key)
17
- return self.queues.find { |queue| queue.name == key }
21
+ queues.find { |queue| queue.name == key }
22
+ end
23
+
24
+ def index_of(queue_name)
25
+ index = queues.index { |queue| queue.name == queue_name }
26
+ return index if index
27
+
28
+ raise Qfill::Errors::InvalidIndex, "Cannot locate index of #{queue_name}"
18
29
  end
19
30
 
20
31
  def reset!
21
32
  self.current_index = 0
22
33
  end
23
34
 
24
- def get_total_elements
25
- self.queues.inject(0) {|counter, queue| counter += queue.elements.length}
35
+ def count_all_elements
36
+ queues.inject(0) { |counter, queue| counter += queue.elements.length }
26
37
  end
27
-
28
38
  end
29
39
  end