Class: RbsDiscard::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RbsDiscard::RakeTask
- Defined in:
- lib/rbs_discard/rake_task.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#signature_root_dir ⇒ Object
Returns the value of attribute signature_root_dir.
Instance Method Summary collapse
- #define_clean_task ⇒ Object
- #define_generate_base_class_task ⇒ Object
- #define_generate_task ⇒ Object
- #define_setup_task ⇒ Object
-
#initialize(name = :"rbs:discard", &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
Constructor Details
#initialize(name = :"rbs:discard", &block) ⇒ RakeTask
Returns a new instance of RakeTask.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rbs_discard/rake_task.rb', line 11 def initialize(name = :"rbs:discard", &block) super() @name = name @signature_root_dir = Rails.root / "sig/discard" block&.call(self) define_clean_task define_generate_base_class_task define_generate_task define_setup_task end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/rbs_discard/rake_task.rb', line 9 def name @name end |
#signature_root_dir ⇒ Object
Returns the value of attribute signature_root_dir.
9 10 11 |
# File 'lib/rbs_discard/rake_task.rb', line 9 def signature_root_dir @signature_root_dir end |
Instance Method Details
#define_clean_task ⇒ Object
57 58 59 60 61 62 |
# File 'lib/rbs_discard/rake_task.rb', line 57 def define_clean_task desc "Clean RBS files for discardable models" task "#{name}:clean" do signature_root_dir.rmtree if signature_root_dir.exist? end end |
#define_generate_base_class_task ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/rbs_discard/rake_task.rb', line 32 def define_generate_base_class_task desc "Generate RBS files for base classes" task "#{name}:base_class:generate": :environment do signature_root_dir.mkpath basedir = Pathname(__FILE__).dirname FileUtils.cp basedir / "sig/discard.rbs", signature_root_dir end end |
#define_generate_task ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rbs_discard/rake_task.rb', line 41 def define_generate_task desc "Generate RBS files for discardable models" task "#{name}:generate" do require "rbs_discard" # load RbsDraper lazily Rails.application.eager_load! RbsDiscard::Discard.all.each do |klass| rbs = RbsDiscard::Discard.class_to_rbs(klass) path = signature_root_dir / "app/models/#{klass.name.to_s.underscore}.rbs" path.dirname.mkpath path.write(rbs) end end end |
#define_setup_task ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rbs_discard/rake_task.rb', line 25 def define_setup_task desc "Run all tasks of rbs_discard" deps = [:"#{name}:clean", :"#{name}:base_class:generate", :"#{name}:generate"] task("#{name}:setup" => deps) end |