botany 0.1.0

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: 1b86a8a6151d29ac61e9efdd5fdb8afccbae6917679b41795e74cecf5b5faedf
4
+ data.tar.gz: bd7a9133a7cd83b033519b80d67104fec4850df3c1557db237658fa37494c4f1
5
+ SHA512:
6
+ metadata.gz: 64d10aeef60321be5d7b15b5443e9ef51f4f88ab3987830258a5b6216513861a837e093cb7e0f563d7ea611827f2940bf819c821ae120f4b18e6275f7316333d
7
+ data.tar.gz: 2e5270d7a3a863ace2d6a2f41ef69c92ef82548afb5260f8b9647d245161666221ef505e5e2e0a7beabf7fa57ed77798676ccfabdf0b962800b17a516bf8c576
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,45 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 3.0
8
+
9
+ Layout/LineLength:
10
+ Max: 120
11
+
12
+ Lint/AmbiguousOperator:
13
+ Enabled: false
14
+
15
+ RSpec/ExampleLength:
16
+ CountAsOne: ['array', 'hash']
17
+
18
+ RSpec/ImplicitExpect:
19
+ EnforcedStyle: should
20
+
21
+ RSpec/NoExpectationExample:
22
+ Enabled: false
23
+
24
+ Style/DefWithParentheses:
25
+ Enabled: false
26
+
27
+ Style/Documentation:
28
+ Enabled: false
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ EnforcedStyle: never
32
+
33
+ Style/MethodDefParentheses:
34
+ EnforcedStyle: require_no_parentheses
35
+
36
+ Style/MethodCallWithArgsParentheses:
37
+ EnforcedStyle: omit_parentheses
38
+
39
+ Style/StringLiterals:
40
+ Enabled: true
41
+ EnforcedStyle: single_quotes
42
+
43
+ Style/StringLiteralsInInterpolation:
44
+ Enabled: true
45
+ EnforcedStyle: single_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-05-20
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 John DeSilva
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,35 @@
1
+ # Botany
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/botany`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_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.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Aesthetikx/botany.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new :spec
5
+
6
+ require 'rubocop/rake_task'
7
+
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
data/exe/botany ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'botany'
4
+
5
+ exit Botany::CLI.run ARGV
data/lib/botany/bot.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Botany
2
+ class Bot
3
+ extend Botany::Enumerating
4
+ extend Botany::Scheduling
5
+ include Botany::Performing
6
+ end
7
+ end
data/lib/botany/cli.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'gli'
2
+
3
+ module Botany
4
+ class CLI
5
+ extend GLI::App
6
+
7
+ version Botany::VERSION
8
+
9
+ program_desc 'Program description'
10
+
11
+ desc 'Update description'
12
+ command :update do |c|
13
+ c.action do |_global_options, _options, _arguments|
14
+ Botany::Scheduling.update_cron!
15
+ end
16
+ end
17
+
18
+ desc 'Run description'
19
+ command :run do |c|
20
+ c.action do |_global_options, _options, arguments|
21
+ task = arguments.first
22
+
23
+ klass_name, method = task.split '.'
24
+
25
+ method ||= 'perform'
26
+
27
+ bot = Object.const_get klass_name
28
+
29
+ bot.new.send method
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ module Botany
2
+ module Enumerating
3
+ prepend Enumerable
4
+
5
+ def all
6
+ klasses = ObjectSpace.each_object Class
7
+
8
+ klasses.select { |klass| klass < self }
9
+ end
10
+
11
+ def each &block
12
+ if block_given?
13
+ all.each &block
14
+ else
15
+ to_enum :each
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Botany
2
+ module Performing
3
+ def perform
4
+ raise Botany::Error, "#{self.class.name} should implement #perform"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'whenever'
2
+
3
+ module Botany
4
+ module Scheduling
5
+ def schedule &block
6
+ if block_given?
7
+ instance_eval &block
8
+ else
9
+ schedule_entries
10
+ end
11
+ end
12
+
13
+ def whenever_configuration_entries
14
+ schedule_entries.map do |entry|
15
+ task = "#{name}.perform"
16
+
17
+ lambda do
18
+ every *entry do
19
+ run_bot task
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.schedule_whenever! config
26
+ config.job_type :run_bot, 'cd :path && bundle exec botany run :task :output'
27
+
28
+ Botany::Bot.each do |bot|
29
+ bot.whenever_configuration_entries.each do |entry|
30
+ config.instance_exec &entry
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.update_cron!
36
+ options = {
37
+ string: 'Botany::Scheduling.schedule_whenever! self',
38
+ update: true,
39
+ identifier: Bundler.root,
40
+ file: __FILE__ # We just need any file to prevent whenever from exiting
41
+ }
42
+
43
+ Signal.trap 'EXIT' do
44
+ Whenever::CommandLine.execute options
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def every *args
51
+ schedule_entries << args
52
+ end
53
+
54
+ def schedule_entries
55
+ @schedule_entries ||= []
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Botany
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/botany.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Botany
2
+ class Error < StandardError; end
3
+ end
4
+
5
+ require_relative 'botany/enumerating'
6
+ require_relative 'botany/performing'
7
+ require_relative 'botany/scheduling'
8
+ require_relative 'botany/version'
9
+
10
+ require_relative 'botany/bot'
11
+
12
+ require_relative 'botany/cli'
data/sig/botany.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Botany
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: botany
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John DeSilva
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: whenever
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: A framework for bots and scheduled tasks
42
+ email:
43
+ - john@aesthetikx.info
44
+ executables:
45
+ - botany
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - exe/botany
56
+ - lib/botany.rb
57
+ - lib/botany/bot.rb
58
+ - lib/botany/cli.rb
59
+ - lib/botany/enumerating.rb
60
+ - lib/botany/performing.rb
61
+ - lib/botany/scheduling.rb
62
+ - lib/botany/version.rb
63
+ - sig/botany.rbs
64
+ homepage: https://github.com/Aesthetikx/botany
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ homepage_uri: https://github.com/Aesthetikx/botany
69
+ source_code_uri: https://github.com/Aesthetikx/botany
70
+ changelog_uri: https://github.com/Aesthetikx/botany/blob/main/CHANGELOG.md
71
+ rubygems_mfa_required: 'true'
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.0.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.4.10
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A framework for bots and scheduled tasks
91
+ test_files: []