Class: RbsActivemodel::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RbsActivemodel::RakeTask
- Defined in:
- lib/rbs_activemodel/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_task ⇒ Object
- #define_setup_task ⇒ Object
-
#initialize(name = :'rbs:activemodel', &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
Constructor Details
#initialize(name = :'rbs:activemodel', &block) ⇒ RakeTask
Returns a new instance of RakeTask.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rbs_activemodel/rake_task.rb', line 10 def initialize(name = :'rbs:activemodel', &block) super() @name = name @signature_root_dir = Pathname(Rails.root / "sig/activemodel") block&.call(self) define_clean_task define_generate_task define_setup_task end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/rbs_activemodel/rake_task.rb', line 8 def name @name end |
#signature_root_dir ⇒ Object
Returns the value of attribute signature_root_dir.
8 9 10 |
# File 'lib/rbs_activemodel/rake_task.rb', line 8 def signature_root_dir @signature_root_dir end |
Instance Method Details
#define_clean_task ⇒ Object
48 49 50 51 52 53 |
# File 'lib/rbs_activemodel/rake_task.rb', line 48 def define_clean_task desc "Clean RBS files for config gem" task("#{name}:clean": :environment) do signature_root_dir.rmtree if signature_root_dir.exist? end end |
#define_generate_task ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rbs_activemodel/rake_task.rb', line 30 def define_generate_task desc "Generate RBS files for activemodel gem" task("#{name}:generate": :environment) do require "rbs_activemodel" # load RbsActivemodel lazily Rails.application.eager_load! RbsActivemodel::ActiveModel.all.each do |klass| rbs = RbsActivemodel::ActiveModel.class_to_rbs(klass) next unless rbs path = signature_root_dir / "app/models/#{klass.name&.underscore}.rbs" path.dirname.mkpath path.write(rbs) end end end |
#define_setup_task ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rbs_activemodel/rake_task.rb', line 23 def define_setup_task desc "Run all tasks of rbs_activemodel" deps = [:"#{name}:clean", :"#{name}:generate"] task("#{name}:setup" => deps) end |