thermite-rails 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +43 -0
  5. data/CHANGELOG.md +14 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +10 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +131 -0
  10. data/Rakefile +15 -0
  11. data/bin/console +15 -0
  12. data/bin/rails +16 -0
  13. data/bin/rake +29 -0
  14. data/bin/rspec +29 -0
  15. data/bin/rubocop +29 -0
  16. data/bin/setup +8 -0
  17. data/lib/thermite/rails.rb +31 -0
  18. data/lib/thermite/rails/cargo_runner.rb +20 -0
  19. data/lib/thermite/rails/check_outdated.rb +19 -0
  20. data/lib/thermite/rails/generators/crate_generator.rb +100 -0
  21. data/lib/thermite/rails/generators/install_generator.rb +14 -0
  22. data/lib/thermite/rails/project.rb +88 -0
  23. data/lib/thermite/rails/railtie.rb +37 -0
  24. data/lib/thermite/rails/root_project.rb +46 -0
  25. data/lib/thermite/rails/tasks/project_rake_task.rb +81 -0
  26. data/lib/thermite/rails/tasks/project_spec_task.rb +33 -0
  27. data/lib/thermite/rails/tasks/project_thermite_build_task.rb +21 -0
  28. data/lib/thermite/rails/tasks/project_thermite_clean_task.rb +21 -0
  29. data/lib/thermite/rails/tasks/project_thermite_test_task.rb +21 -0
  30. data/lib/thermite/rails/tasks/project_thermite_update_task.rb +28 -0
  31. data/lib/thermite/rails/tasks/root_project_rake_task.rb +74 -0
  32. data/lib/thermite/rails/tasks/root_project_spec_task.rb +40 -0
  33. data/lib/thermite/rails/tasks/root_project_thermite_build_task.rb +27 -0
  34. data/lib/thermite/rails/tasks/root_project_thermite_clean_task.rb +27 -0
  35. data/lib/thermite/rails/tasks/root_project_thermite_test_task.rb +27 -0
  36. data/lib/thermite/rails/tasks/root_project_thermite_update_task.rb +27 -0
  37. data/lib/thermite/rails/tasks/rspec.rake +14 -0
  38. data/lib/thermite/rails/tasks/thermite.rake +18 -0
  39. data/lib/thermite/rails/version.rb +7 -0
  40. data/thermite-rails.gemspec +47 -0
  41. metadata +237 -0
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ require 'rspec/rails'
6
+ rescue LoadError
7
+ return
8
+ end
9
+
10
+ require_relative 'project_rake_task'
11
+
12
+ module Thermite
13
+ module Rails
14
+ module Tasks
15
+ class ProjectSpecTask < ProjectRakeTask
16
+ # @return [String]
17
+ def task_name
18
+ "spec:crates:#{crate_name_for_ruby}"
19
+ end
20
+
21
+ def define_rake_task
22
+ prereqs = ["thermite:build:#{crate_name_for_ruby}"]
23
+ prereqs.push('spec:prepare') if Rake::Task.task_defined?('spec:prepare')
24
+
25
+ desc "Run the code examples in #{crate_name}"
26
+ RSpec::Core::RakeTask.new(task_name => prereqs) do |t|
27
+ t.pattern = "#{@project.spec_path}/**/*_spec.rb"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'project_rake_task'
4
+
5
+ module Thermite
6
+ module Rails
7
+ module Tasks
8
+ class ProjectThermiteBuildTask < ProjectRakeTask
9
+ # @return [String]
10
+ def task_name
11
+ "thermite:build:#{crate_name_for_ruby}"
12
+ end
13
+
14
+ def define_rake_task
15
+ desc "Using thermite, build crate #{crate_name}"
16
+ task(task_name) { run_task('thermite:build') }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'project_rake_task'
4
+
5
+ module Thermite
6
+ module Rails
7
+ module Tasks
8
+ class ProjectThermiteCleanTask < ProjectRakeTask
9
+ # @return [String]
10
+ def task_name
11
+ "thermite:clean:#{crate_name_for_ruby}"
12
+ end
13
+
14
+ def define_rake_task
15
+ desc "Using thermite, clean crate #{crate_name}"
16
+ task(task_name) { run_task('thermite:clean') }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'project_rake_task'
4
+
5
+ module Thermite
6
+ module Rails
7
+ module Tasks
8
+ class ProjectThermiteTestTask < ProjectRakeTask
9
+ # @return [String]
10
+ def task_name
11
+ "thermite:test:#{crate_name_for_ruby}"
12
+ end
13
+
14
+ def define_rake_task
15
+ desc "Using thermite, (cargo) test crate #{crate_name}"
16
+ task(task_name) { run_task('thermite:test') }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'project_rake_task'
4
+ require_relative '../cargo_runner'
5
+
6
+ module Thermite
7
+ module Rails
8
+ module Tasks
9
+ class ProjectThermiteUpdateTask < ProjectRakeTask
10
+ # @return [String]
11
+ def task_name
12
+ "thermite:update:#{crate_name_for_ruby}"
13
+ end
14
+
15
+ def define_rake_task
16
+ desc "Using thermite, (cargo) update crate #{crate_name}"
17
+ task(task_name) do
18
+ color_puts("Running task: #{task_name}", :blue)
19
+
20
+ Thermite::Rails::CargoRunner.new(@project.config).tap do |cargo_runner|
21
+ cargo_runner.run_cargo('update')
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/tasklib'
4
+
5
+ module Thermite
6
+ module Rails
7
+ module Tasks
8
+ # This is intended as a base class for defining other Rake tasks at the
9
+ # Rails/root project level (as opposed to the crate/project level).
10
+ class RootProjectRakeTask < ::Rake::TaskLib
11
+ def initialize
12
+ @root_project = Thermite::Rails.root_project
13
+ end
14
+
15
+ # @return [String]
16
+ def task_name
17
+ raise 'Define in child'
18
+ end
19
+
20
+ # @return [Class]
21
+ def project_task_class
22
+ raise 'Define in child'
23
+ end
24
+
25
+ # Text the task should list for its `desc`.
26
+ #
27
+ # @return [String]
28
+ def desc_text
29
+ raise 'Define in child'
30
+ end
31
+
32
+ # Method that does the standard Rake task DSL calls for defining the task.
33
+ def define_rake_task
34
+ return if Rake::Task.task_defined?(task_name)
35
+
36
+ desc(desc_text)
37
+ task task_name => prerequisite_tasks
38
+ end
39
+
40
+ # A list of all of the tasks this take should run.
41
+ #
42
+ # @return [Array<String>]
43
+ def prerequisite_tasks
44
+ project_task_names
45
+ end
46
+
47
+ # Iterates through each project task and calls `#define_rake_task`.
48
+ def define_project_rake_tasks
49
+ project_tasks.each(&:define_rake_task)
50
+ end
51
+
52
+ # @return [Array<String>]
53
+ def project_task_names
54
+ project_tasks.map(&:task_name)
55
+ end
56
+
57
+ # @return [Array<Class>]
58
+ def project_tasks
59
+ @project_tasks ||= @root_project.projects.map do |project|
60
+ p = project_task_class.new(project)
61
+ p.define_rake_task unless p.defined?
62
+
63
+ p
64
+ end
65
+ end
66
+
67
+ # @return [Boolean] Has a task with this name already been defined?
68
+ def defined?
69
+ Rake::Task.task_defined?(task_name)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ require 'rspec/rails'
6
+ rescue LoadError
7
+ return
8
+ end
9
+
10
+ require_relative 'root_project_rake_task'
11
+ require_relative 'project_spec_task'
12
+
13
+ module Thermite
14
+ module Rails
15
+ module Tasks
16
+ class RootProjectSpecTask < RootProjectRakeTask
17
+ DESC = 'Run code examples for all crates'
18
+ NAME = 'spec:crates'
19
+
20
+ def task_name
21
+ NAME
22
+ end
23
+
24
+ def desc_text
25
+ DESC
26
+ end
27
+
28
+ def project_task_class
29
+ ProjectSpecTask
30
+ end
31
+
32
+ def project_tasks
33
+ @project_tasks ||= @root_project.projects_with_specs.map do |project|
34
+ project_task_class.new(project)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'root_project_rake_task'
4
+ require_relative 'project_thermite_build_task'
5
+
6
+ module Thermite
7
+ module Rails
8
+ module Tasks
9
+ class RootProjectThermiteBuildTask < RootProjectRakeTask
10
+ DESC = 'Using thermite, build all crates'
11
+ NAME = 'thermite:build_all'
12
+
13
+ def task_name
14
+ NAME
15
+ end
16
+
17
+ def desc_text
18
+ DESC
19
+ end
20
+
21
+ def project_task_class
22
+ ProjectThermiteBuildTask
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'root_project_rake_task'
4
+ require_relative 'project_thermite_clean_task'
5
+
6
+ module Thermite
7
+ module Rails
8
+ module Tasks
9
+ class RootProjectThermiteCleanTask < RootProjectRakeTask
10
+ DESC = 'Using thermite, clean all crates'
11
+ NAME = 'thermite:clean_all'
12
+
13
+ def task_name
14
+ NAME
15
+ end
16
+
17
+ def desc_text
18
+ DESC
19
+ end
20
+
21
+ def project_task_class
22
+ ProjectThermiteCleanTask
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'root_project_rake_task'
4
+ require_relative 'project_thermite_test_task'
5
+
6
+ module Thermite
7
+ module Rails
8
+ module Tasks
9
+ class RootProjectThermiteTestTask < RootProjectRakeTask
10
+ DESC = 'Using thermite, test all crates'
11
+ NAME = 'thermite:test_all'
12
+
13
+ def task_name
14
+ NAME
15
+ end
16
+
17
+ def desc_text
18
+ DESC
19
+ end
20
+
21
+ def project_task_class
22
+ ProjectThermiteTestTask
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'root_project_rake_task'
4
+ require_relative 'project_thermite_update_task'
5
+
6
+ module Thermite
7
+ module Rails
8
+ module Tasks
9
+ class RootProjectThermiteUpdateTask < RootProjectRakeTask
10
+ DESC = 'Using thermite, (cargo) update all crates'
11
+ NAME = 'thermite:update_all'
12
+
13
+ def task_name
14
+ NAME
15
+ end
16
+
17
+ def desc_text
18
+ DESC
19
+ end
20
+
21
+ def project_task_class
22
+ ProjectThermiteUpdateTask
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ return unless defined?(::RSpec)
4
+
5
+ projects_with_specs = Thermite::Rails.root_project.projects_with_specs
6
+
7
+ return if projects_with_specs.empty?
8
+
9
+ require_relative 'root_project_spec_task'
10
+
11
+ Thermite::Rails::Tasks::RootProjectSpecTask.new.tap do |builder|
12
+ builder.define_project_rake_tasks
13
+ builder.define_rake_task
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'root_project_thermite_build_task'
4
+ require_relative 'root_project_thermite_clean_task'
5
+ require_relative 'root_project_thermite_test_task'
6
+ require_relative 'root_project_thermite_update_task'
7
+
8
+ [
9
+ Thermite::Rails::Tasks::RootProjectThermiteBuildTask,
10
+ Thermite::Rails::Tasks::RootProjectThermiteCleanTask,
11
+ Thermite::Rails::Tasks::RootProjectThermiteTestTask,
12
+ Thermite::Rails::Tasks::RootProjectThermiteUpdateTask
13
+ ].each do |task_class|
14
+ task_class.new.tap do |builder|
15
+ builder.define_project_rake_tasks
16
+ builder.define_rake_task
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thermite
4
+ module Rails
5
+ VERSION = '0.2.0'
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'thermite/rails/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'thermite-rails'
9
+ spec.version = Thermite::Rails::VERSION
10
+ spec.authors = ['Steve Loveless']
11
+ spec.email = ['steve@agrian.com']
12
+
13
+ spec.summary = 'Use thermite gems in Rails.'
14
+ spec.description = spec.summary
15
+ spec.homepage = 'https://bitbucket.org/agrian/thermite-rails'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against " \
24
+ # "public gem pushes."
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+
31
+ spec.bindir = 'bin'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_dependency 'rails', '>= 5.0'
36
+ spec.add_dependency 'rake', '>= 10.0'
37
+ spec.add_dependency 'thermite', '~> 0.13'
38
+ spec.add_dependency 'thor'
39
+ spec.add_dependency 'tomlrb', '~> 1.2'
40
+
41
+ spec.add_development_dependency 'bundler', '~> 1.16'
42
+ spec.add_development_dependency 'pry'
43
+ spec.add_development_dependency 'rake', '>= 10.0'
44
+ spec.add_development_dependency 'rspec-rails', '~> 3.0'
45
+ spec.add_development_dependency 'rubocop'
46
+ spec.add_development_dependency 'rubocop-checkstyle_formatter'
47
+ end