Class: RbsActivesupport::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RbsActivesupport::RakeTask
- Defined in:
- lib/rbs_activesupport/rake_task.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
: Symbol.
-
#signature_root_dir ⇒ Object
: Pathname.
-
#target_directories ⇒ Object
: Array.
Instance Method Summary collapse
-
#define_clean_task ⇒ Object
: void.
-
#define_generate_task ⇒ Object
: void.
-
#define_setup_task ⇒ Object
: void.
-
#initialize(name = :"rbs:activesupport", &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
Constructor Details
#initialize(name = :"rbs:activesupport", &block) ⇒ RakeTask
Returns a new instance of RakeTask.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rbs_activesupport/rake_task.rb', line 16 def initialize(name = :"rbs:activesupport", &block) #: void super() @name = name @signature_root_dir = Pathname(Rails.root / "sig/activesupport") @target_directories = [Rails.root / "app"] block&.call(self) define_clean_task define_generate_task define_setup_task end |
Instance Attribute Details
#name ⇒ Object
: Symbol
8 9 10 |
# File 'lib/rbs_activesupport/rake_task.rb', line 8 def name @name end |
#signature_root_dir ⇒ Object
: Pathname
9 10 11 |
# File 'lib/rbs_activesupport/rake_task.rb', line 9 def signature_root_dir @signature_root_dir end |
#target_directories ⇒ Object
: Array
10 11 12 |
# File 'lib/rbs_activesupport/rake_task.rb', line 10 def target_directories @target_directories end |
Instance Method Details
#define_clean_task ⇒ Object
: void
59 60 61 62 63 64 |
# File 'lib/rbs_activesupport/rake_task.rb', line 59 def define_clean_task #: void desc "Clean RBS files for config gem" task "#{name}:clean" do signature_root_dir.rmtree if signature_root_dir.exist? end end |
#define_generate_task ⇒ Object
: void
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rbs_activesupport/rake_task.rb', line 37 def define_generate_task #: void desc "Generate RBS files for activesupport gem" task("#{name}:generate": :environment) do require "rbs_activesupport" # load RbsActivesupport lazily Rails.application.eager_load! signature_root_dir.mkpath target_directories.each do |dir| dir.glob("**/*.rb").each do |file| rbs = Generator.generate(file, rbs_builder) next unless rbs rbs_path = signature_root_dir / file.sub_ext(".rbs").relative_path_from(Rails.root) rbs_path.dirname.mkpath rbs_path.write(rbs) end end end end |
#define_setup_task ⇒ Object
: void
30 31 32 33 34 35 |
# File 'lib/rbs_activesupport/rake_task.rb', line 30 def define_setup_task #: void desc "Run all tasks of rbs_activesupport" deps = [:"#{name}:clean", :"#{name}:generate"] task("#{name}:setup" => deps) end |