plantae 0.1.10

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc5369384b082e1299a38928243064344e8f13a5ed51d5560926de13eb57c202
4
+ data.tar.gz: 2f4625af9abb7ef6f38173f33b5ee7e13578cce330f14e2abd2df87aaa5f7505
5
+ SHA512:
6
+ metadata.gz: e8457bf9e29e336fcb064e57137a0554eef0aafbbafe29b6dc6136725e3d06db9cf7810bd567b0df374b3b823500c9631e72671b6dfb1a4c1c205eb5fec15276
7
+ data.tar.gz: 81f62c35f92f7489ef2627edeceb37e841c620429e21d57dd9540103caeeff35ce20d3dfd5df926971a45b27d0448ad7640dc981b7e51cb1e1da3d5694fa8d36
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:entdec) { |repo_name| "git@github.com:entdec/#{repo_name}.git" }
4
+
5
+ # Specify your gem's dependencies in plantae.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 12.0"
9
+ gem "minitest", "~> 5.0"
10
+ gem 'auxilium', '~> 3.0', entdec: 'auxilium'
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ GIT
2
+ remote: git@github.com:entdec/auxilium.git
3
+ revision: 32f259e2327ba5f3da7210679e08a94f48325945
4
+ specs:
5
+ auxilium (3.0.15)
6
+ actionpack (> 5.1)
7
+ activemodel (> 5.1)
8
+ activesupport (> 5.1)
9
+ pundit (> 2)
10
+ responders (> 3)
11
+ rolify (> 5)
12
+
13
+ PATH
14
+ remote: .
15
+ specs:
16
+ plantae (0.1.10)
17
+ activesupport (>= 5.2)
18
+
19
+ GEM
20
+ remote: https://rubygems.org/
21
+ specs:
22
+ actionpack (7.0.1)
23
+ actionview (= 7.0.1)
24
+ activesupport (= 7.0.1)
25
+ rack (~> 2.0, >= 2.2.0)
26
+ rack-test (>= 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
29
+ actionview (7.0.1)
30
+ activesupport (= 7.0.1)
31
+ builder (~> 3.1)
32
+ erubi (~> 1.4)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
35
+ activemodel (7.0.1)
36
+ activesupport (= 7.0.1)
37
+ activesupport (7.0.1)
38
+ concurrent-ruby (~> 1.0, >= 1.0.2)
39
+ i18n (>= 1.6, < 2)
40
+ minitest (>= 5.1)
41
+ tzinfo (~> 2.0)
42
+ builder (3.2.4)
43
+ concurrent-ruby (1.1.9)
44
+ crass (1.0.6)
45
+ erubi (1.10.0)
46
+ i18n (1.8.11)
47
+ concurrent-ruby (~> 1.0)
48
+ loofah (2.13.0)
49
+ crass (~> 1.0.2)
50
+ nokogiri (>= 1.5.9)
51
+ method_source (1.0.0)
52
+ mini_portile2 (2.7.1)
53
+ minitest (5.20.0)
54
+ nokogiri (1.13.1)
55
+ mini_portile2 (~> 2.7.0)
56
+ racc (~> 1.4)
57
+ pundit (2.1.1)
58
+ activesupport (>= 3.0.0)
59
+ racc (1.6.0)
60
+ rack (2.2.3)
61
+ rack-test (1.1.0)
62
+ rack (>= 1.0, < 3)
63
+ rails-dom-testing (2.0.3)
64
+ activesupport (>= 4.2.0)
65
+ nokogiri (>= 1.6)
66
+ rails-html-sanitizer (1.4.2)
67
+ loofah (~> 2.3)
68
+ railties (7.0.1)
69
+ actionpack (= 7.0.1)
70
+ activesupport (= 7.0.1)
71
+ method_source
72
+ rake (>= 12.2)
73
+ thor (~> 1.0)
74
+ zeitwerk (~> 2.5)
75
+ rake (12.3.3)
76
+ responders (3.0.1)
77
+ actionpack (>= 5.0)
78
+ railties (>= 5.0)
79
+ rolify (6.0.0)
80
+ thor (1.2.1)
81
+ tzinfo (2.0.4)
82
+ concurrent-ruby (~> 1.0)
83
+ zeitwerk (2.5.3)
84
+
85
+ PLATFORMS
86
+ ruby
87
+
88
+ DEPENDENCIES
89
+ auxilium (~> 3.0)!
90
+ minitest (~> 5.0)
91
+ plantae!
92
+ rake (~> 12.0)
93
+
94
+ BUNDLED WITH
95
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Mark Cornelissen
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,40 @@
1
+ ge# Plantae
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/plantae`. 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 'plantae'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install plantae
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 test` 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]/plantae.
36
+
37
+
38
+ ## License
39
+
40
+ 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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
13
+
14
+ # Adds the Auxilium semver task
15
+ spec = Gem::Specification.find_by_name 'auxilium'
16
+ load "#{spec.gem_dir}/lib/tasks/semver.rake"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "plantae"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plantae
4
+ class ActiveJobAdapter
5
+ def enqueue(job)
6
+ job.perform_now
7
+ end
8
+
9
+ def enqueue_at(job, timestamp)
10
+ raise 'cannot handle jobs this far in the future' if Time.current.to_f - timestamp > 2
11
+ job.perform_now
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plantae
4
+ # Represents a scenario
5
+ class Scenario
6
+ attr_reader :name, :block
7
+
8
+ # @param name [String] scenario name
9
+ # @param block [Proc] scenario to execute
10
+ def initialize(name, &block)
11
+ @name = name
12
+ @block = block
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scenario'
4
+ require 'active_support/callbacks'
5
+ require 'active_support/core_ext/module/delegation'
6
+ require_relative 'active_job_adapter'
7
+
8
+ module Plantae
9
+ # Extend this class to create your own seeders
10
+ class Seeder
11
+ include ActiveSupport::Callbacks
12
+ define_callbacks :create, :destroy
13
+ delegate :scenarios, to: :class
14
+
15
+ class << self
16
+ # Run the given methods with the ActiveJob inline adapter temporarily enabled
17
+ def with_inline_jobs(*names)
18
+ names.each do |name|
19
+ m = instance_method(name)
20
+ @@semaphore ||= Mutex.new
21
+ @@in_mutex ||= false
22
+
23
+ only_kwargs = m.parameters.count.positive? && m.parameters.all? { |i| i.first == :key }
24
+
25
+ the_new_method = proc do |*args|
26
+ the_code = proc do
27
+ old_queue_adapter = ActiveJob::Base.queue_adapter
28
+ ActiveJob::Base.queue_adapter = ActiveJobAdapter.new
29
+
30
+ kwargs = args.last.is_a?(Hash) ? args.pop : {}
31
+
32
+ if only_kwargs
33
+ m.bind(self).call(**kwargs)
34
+ else
35
+ m.bind(self).call(*args, **kwargs)
36
+ end
37
+ ensure
38
+ ActiveJob::Base.queue_adapter = old_queue_adapter
39
+ end
40
+
41
+ if @@in_mutex
42
+ result = the_code.call
43
+ else
44
+ @@semaphore.synchronize do
45
+ @@in_mutex = true
46
+ result = the_code.call
47
+ ensure
48
+ @@in_mutex = false
49
+ end
50
+ end
51
+
52
+ result
53
+ end
54
+
55
+ define_method(name, the_new_method)
56
+ end
57
+ end
58
+
59
+ # Run all public instance methos with the with_inline_jobs method
60
+ def all_public_methods_with_inline_jobs
61
+ with_inline_jobs(*public_instance_methods(false))
62
+ end
63
+
64
+ def scenarios
65
+ @scenarios || []
66
+ end
67
+
68
+ # Create scenarios in your seeder using the following format:
69
+ #
70
+ # scenario "this is my scenario" do
71
+ # ...
72
+ # end
73
+ def scenario(name, &block)
74
+ @scenarios ||= []
75
+ @scenarios << Scenario.new(name, &block)
76
+ end
77
+
78
+ # Define code to execute on create, this is used to create
79
+ # preconditions before running any scenarios.
80
+ def create(*args, &block)
81
+ set_callback(:create, :before, *args, &block)
82
+ end
83
+
84
+ # Define code to execute on destroy, this is used to clean up
85
+ # the items created through the seeder.
86
+ def destroy(*args, &block)
87
+ set_callback(:destroy, :before, *args, &block)
88
+ end
89
+ end
90
+
91
+ # Runs all create blocks
92
+ def create
93
+ run_callbacks :create
94
+ end
95
+
96
+ # Runs all destroy blocks
97
+ def destroy
98
+ run_callbacks :destroy
99
+ end
100
+
101
+ # Run scenario(s)
102
+ #
103
+ # @param name [String, nil] when given only run the scenario matching the given name and skip the create logic
104
+ def run(name = nil)
105
+ create unless name.present?
106
+
107
+ scenarios.select { |scenario| name.blank? || scenario.name == name }
108
+ .each do |scenario|
109
+ instance_exec(&scenario.block)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plantae
4
+ VERSION = '0.1.10'
5
+ end
data/lib/plantae.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'plantae/version'
4
+ require 'plantae/seeder'
data/plantae.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/plantae/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'plantae'
5
+ spec.version = Plantae::VERSION
6
+ spec.authors = ['Mark Cornelissen']
7
+ spec.email = ['mark@boxture.com']
8
+
9
+ spec.summary = %q{Plantae helps you put seed data in your projects.}
10
+ spec.homepage = 'https://code.entdec.com/components/plantae'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'activesupport', '>= 5.2'
25
+
26
+ spec.add_development_dependency 'auxilium', '~> 0.2'
27
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plantae
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - Mark Cornelissen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: auxilium
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ description:
42
+ email:
43
+ - mark@boxture.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/plantae.rb
58
+ - lib/plantae/active_job_adapter.rb
59
+ - lib/plantae/scenario.rb
60
+ - lib/plantae/seeder.rb
61
+ - lib/plantae/version.rb
62
+ - plantae.gemspec
63
+ homepage: https://code.entdec.com/components/plantae
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://code.entdec.com/components/plantae
68
+ source_code_uri: https://code.entdec.com/components/plantae
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.3.7
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Plantae helps you put seed data in your projects.
88
+ test_files: []