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