basket 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: 20ae2ec64c54d8a1ae452a284e20f8bc2393318f7333bcbc7152bf24236e4b26
4
+ data.tar.gz: 8cb26c727cbc2c49ea906a6f949c6b1a8631a9bea3200b446f7ee2b4a8c15a59
5
+ SHA512:
6
+ metadata.gz: 7f0b0410eb3ad97c9ca857e875c031d5d0bbee7183f62dc22d087424d503c16b2f5c7080aa1f458b89a07719eace55fae46b87f6df079cc8a4cc341b8a00f17a
7
+ data.tar.gz: a6924dd3d2e1b3d3b731cbcbe2fa473718785244e432fd87a9de11e29a3f0275380581dbf5844a5e0d7bbbb6377a262e6592a657f0f1df5d5f0517f0697869ed
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-15
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nichol.alexander@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in basket.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ basket (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.3)
12
+ language_server-protocol (3.17.0.3)
13
+ parallel (1.22.1)
14
+ parser (3.2.1.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ regexp_parser (2.7.0)
19
+ rexml (3.2.5)
20
+ rspec (3.12.0)
21
+ rspec-core (~> 3.12.0)
22
+ rspec-expectations (~> 3.12.0)
23
+ rspec-mocks (~> 3.12.0)
24
+ rspec-core (3.12.1)
25
+ rspec-support (~> 3.12.0)
26
+ rspec-expectations (3.12.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.12.0)
29
+ rspec-mocks (3.12.3)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-support (3.12.0)
33
+ rubocop (1.44.1)
34
+ json (~> 2.3)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.2.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rubocop-ast (>= 1.24.1, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 2.4.0, < 3.0)
43
+ rubocop-ast (1.26.0)
44
+ parser (>= 3.2.1.0)
45
+ rubocop-performance (1.15.2)
46
+ rubocop (>= 1.7.0, < 2.0)
47
+ rubocop-ast (>= 0.4.0)
48
+ ruby-progressbar (1.11.0)
49
+ standard (1.24.3)
50
+ language_server-protocol (~> 3.17.0.2)
51
+ rubocop (= 1.44.1)
52
+ rubocop-performance (= 1.15.2)
53
+ unicode-display_width (2.4.2)
54
+
55
+ PLATFORMS
56
+ arm64-darwin-22
57
+ x86_64-darwin-20
58
+ x86_64-linux
59
+
60
+ DEPENDENCIES
61
+ basket!
62
+ rake (~> 13.0)
63
+ rspec (~> 3.0)
64
+ standard (~> 1.3)
65
+
66
+ BUNDLED WITH
67
+ 2.4.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 nichol alexander
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,108 @@
1
+ # It would be silly to use this gem because it doesn't work yet.
2
+ # Basket
3
+
4
+ A farmer doesn't walk down to the chicken coop, grab an egg, go back to the kitchen, go back to the coop, go back to the kitchen, etc, etc. They take a basket with them, and as the chickens lay their eggs, they fill up the basket and when the basket is full they go make something with them! I would make a quiche, but that's besides the case.
5
+
6
+ `Basket` lets you do just that. Collect items until your basket is full and then, when it is, go do something with them!
7
+
8
+ ## Installation
9
+
10
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19
+
20
+ ## Usage
21
+
22
+ Add items to your basket as they come along. They might come along quickly, or there might be a delay between them. Regardless, you want to collect items into your basket before going and doing something with them.
23
+
24
+ ```ruby
25
+ while chicken.laying do
26
+ egg = { egg: {color: brown, size: medium}}
27
+ Basket.add('QuicheBasket', egg)
28
+ end
29
+ ```
30
+
31
+ The item added to the basket can be any data you want! If you are using the in memory Queue, it is fine to store Ruby objects, but if you have a different backend, it might be better to stick to easily serializable objects.
32
+
33
+ ```ruby
34
+ class QuicheBasket
35
+ include Basket::Batcher
36
+
37
+ basket_options length: 15
38
+
39
+ def perform
40
+ eggs = []
41
+ batch.each do | egg |
42
+ # do some processing on each element of the batch. In this case there will be 15 eggs.
43
+ egg = Egg.new(egg)
44
+ egg.wash!
45
+ eggs << egg
46
+ end
47
+
48
+ # If you want to do something directly inline:
49
+ Quiche.make(eggs)
50
+
51
+ # If you want to do something out of a request response cycle,
52
+ # call out to your favorite background processing framework:
53
+ BrunchInviteJob.perform_async
54
+ end
55
+
56
+ # There are four callbacks to the lifecycle of a basket.
57
+ # :on_success, :on_failure, :on_add, :check_length
58
+ # They can be used like this:
59
+ on_success: :let_chickens_rest
60
+
61
+ def let_chickens_rest
62
+ ...
63
+ end
64
+
65
+ end
66
+ ```
67
+
68
+ The perform method will be called after there have been 15 elements added to the batch. The callbacks are lifecycle callbacks on the existing batch. `on_add` takes an argument of the element that is being added. The elements are just a hash. `on_success` and `on_failure` give access to the whole batch.
69
+
70
+ ## Development
71
+
72
+ 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.
73
+
74
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/basket. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/basket/blob/main/CODE_OF_CONDUCT.md).
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+
84
+ ## Code of Conduct
85
+
86
+ Everyone interacting in the Basket project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/basket/blob/main/CODE_OF_CONDUCT.md).
87
+
88
+
89
+
90
+ ## Ideas
91
+
92
+ 1. Can the callbacks support ActiveSupport Notifications?
93
+ - ActiveSupport::Callbacks extraction of callbacks
94
+ 2. Batch can be postgres json blob or Redis! - Backend system
95
+ ~~3. Does not execute in line~~For now.
96
+ ~~4. Use ActiveJob for background execution.~~ It's up to you to handle a full basket how you want.
97
+ ~~5. "Buffer", "collection", "queue"~~ Basket.
98
+ 6. Default trigger is just queue length.
99
+ 7. Expose basket_options trigger: :check_some_thing_lambda
100
+ 8. Redis push pop.
101
+ 9. Make queue ephemeral?
102
+ 10. Define gotchas but don't solve them.
103
+ 11. Redis fetch / Super Fetch?
104
+ 12. Configuration.
105
+
106
+ https://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html
107
+
108
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard:fix]
data/basket.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/basket/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "basket"
7
+ spec.version = Basket::VERSION
8
+ spec.authors = ["nichol alexander"]
9
+ spec.email = ["nichol.alexander@gmail.com "]
10
+
11
+ spec.summary = "Wait until you have a bunch of things, then do something."
12
+ spec.description = "This is a longer description."
13
+ spec.homepage = "https://github.com/nicholalexander/basket"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/nicholalexander/basket"
19
+ spec.metadata["changelog_uri"] = "https://github.com/nicholalexander/basket/blob/main/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 into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
@@ -0,0 +1,4 @@
1
+ module Basket
2
+ module Batcher
3
+ end
4
+ end
@@ -0,0 +1,24 @@
1
+ module Basket
2
+ class HashBackend
3
+ attr_reader :data
4
+
5
+ def initialize
6
+ @data = {}
7
+ end
8
+
9
+ def push(queue, data)
10
+ @data[queue] = [] if @data[queue].nil?
11
+ @data[queue] <<= data
12
+ end
13
+
14
+ def length(queue)
15
+ return 0 if @data[queue].nil?
16
+
17
+ @data[queue].length
18
+ end
19
+
20
+ def pop_all(queue)
21
+ @data.delete(queue)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Basket
2
+ class Queue
3
+ def initialize(backend = HashBackend.new)
4
+ @backend = backend
5
+ end
6
+
7
+ def push(queue, data)
8
+ @backend.push(queue, data)
9
+ length(queue)
10
+ end
11
+
12
+ def length(queue)
13
+ @backend.length(queue)
14
+ end
15
+
16
+ def pop_all(queue)
17
+ @backend.pop_all(queue)
18
+ end
19
+
20
+ def data
21
+ @backend.data
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Basket
4
+ VERSION = "0.0.1"
5
+ end
data/lib/basket.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "basket/batcher"
4
+ require_relative "basket/hash_backend"
5
+ require_relative "basket/queue"
6
+ require_relative "basket/version"
7
+
8
+ module Basket
9
+ class Error < StandardError; end
10
+
11
+ def self.add(queue, data)
12
+ queue_length = Basket::Queue.push(queue, data)
13
+ queue_class = queue.constantize.new
14
+ return unless queue_length == queue_class.batcher.options.queue_length
15
+
16
+ queue_class.perform
17
+ end
18
+ end
data/sig/basket.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Basket
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - nichol alexander
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-02-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a longer description.
14
+ email:
15
+ - 'nichol.alexander@gmail.com '
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".standard.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - basket.gemspec
30
+ - lib/basket.rb
31
+ - lib/basket/batcher.rb
32
+ - lib/basket/hash_backend.rb
33
+ - lib/basket/queue.rb
34
+ - lib/basket/version.rb
35
+ - sig/basket.rbs
36
+ homepage: https://github.com/nicholalexander/basket
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/nicholalexander/basket
41
+ source_code_uri: https://github.com/nicholalexander/basket
42
+ changelog_uri: https://github.com/nicholalexander/basket/blob/main/CHANGELOG.md
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.6.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.4.7
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Wait until you have a bunch of things, then do something.
62
+ test_files: []