Class: RbsDraper::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RbsDraper::RakeTask
- Defined in:
- lib/rbs_draper/rake_task.rb
Instance Attribute Summary collapse
-
#mapping ⇒ Object
Returns the value of attribute mapping.
-
#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_decoratables_generate_task ⇒ Object
- #define_decorators_generate_task ⇒ Object
- #define_setup_task ⇒ Object
-
#initialize(name = :'rbs:draper', &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
Constructor Details
#initialize(name = :'rbs:draper', &block) ⇒ RakeTask
Returns a new instance of RakeTask.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbs_draper/rake_task.rb', line 13 def initialize(name = :'rbs:draper', &block) super() @name = name @signature_root_dir = Pathname(Rails.root / "sig/draper") @mapping = -> { {} } block&.call(self) define_clean_task define_base_class_generate_task define_decoratables_generate_task define_decorators_generate_task define_setup_task end |
Instance Attribute Details
#mapping ⇒ Object
Returns the value of attribute mapping.
11 12 13 |
# File 'lib/rbs_draper/rake_task.rb', line 11 def mapping @mapping end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/rbs_draper/rake_task.rb', line 11 def name @name end |
#signature_root_dir ⇒ Object
Returns the value of attribute signature_root_dir.
11 12 13 |
# File 'lib/rbs_draper/rake_task.rb', line 11 def signature_root_dir @signature_root_dir end |
Instance Method Details
#define_base_class_generate_task ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rbs_draper/rake_task.rb', line 44 def define_base_class_generate_task desc "Generate RBS files for base classes" task("#{name}:base_class:generate": :environment) do require "rbs_draper" # load RbsDraper lazily signature_root_dir.mkpath basedir = Pathname(__FILE__).dirname FileUtils.cp basedir / "sig/decoratable.rbs", signature_root_dir FileUtils.cp basedir / "sig/decorator.rbs", signature_root_dir end end |
#define_clean_task ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rbs_draper/rake_task.rb', line 37 def define_clean_task desc "Clean up generated RBS files" task("#{name}:clean": :environment) do sh "rm", "-rf", signature_root_dir.to_s end end |
#define_decoratables_generate_task ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rbs_draper/rake_task.rb', line 57 def define_decoratables_generate_task desc "Generate RBS files for decoratable models" task("#{name}:decoratables:generate": :environment) do require "rbs_draper" # load RbsDraper lazily Rails.application.eager_load! RbsDraper::Decoratable.all.each do |klass| path = signature_root_dir / "app/models/#{klass.name.to_s.underscore}.rbs" path.dirname.mkpath rbs = RbsDraper::Decoratable.class_to_rbs(klass) path.write rbs if rbs end end end |
#define_decorators_generate_task ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rbs_draper/rake_task.rb', line 73 def define_decorators_generate_task desc "Generate RBS files for decorators" task("#{name}:decorators:generate": :environment) do Rails.application.eager_load! decorated_classes = mapping.call Draper::Decorator.descendants.each do |klass| path = signature_root_dir / "app/decorators/#{klass.name.underscore}.rbs" path.dirname.mkpath rbs = RbsDraper::Decorator.class_to_rbs(klass, rbs_builder, decorated_class: decorated_classes[klass]) path.write rbs if rbs end end end |
#define_setup_task ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rbs_draper/rake_task.rb', line 29 def define_setup_task desc "Run all tasks of rbs_draper" deps = [:"#{name}:clean", :"#{name}:base_class:generate", :"#{name}:decoratables:generate", :"#{name}:decorators:generate"] task("#{name}:setup": deps) end |