Class: RbsConfig::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RbsConfig::RakeTask
- Defined in:
- lib/rbs_config/rake_task.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#files ⇒ Object
Returns the value of attribute files.
-
#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.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #define_clean_task ⇒ Object
- #define_generate_task ⇒ Object
- #define_setup_task ⇒ Object
-
#initialize(name = :'rbs:config', &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
Constructor Details
#initialize(name = :'rbs:config', &block) ⇒ RakeTask
Returns a new instance of RakeTask.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbs_config/rake_task.rb', line 10 def initialize(name = :'rbs:config', &block) super() @name = name @type = :config @class_name = "Settings" @files = [Pathname(Rails.root / "config/settings.yml"), Pathname(Rails.root / "config/settings.local.yml"), Pathname(Rails.root / "config/settings/production.yml")] @mapping = {} @signature_root_dir = Pathname(Rails.root / "sig/config") block&.call(self) define_clean_task define_generate_task define_setup_task end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
8 9 10 |
# File 'lib/rbs_config/rake_task.rb', line 8 def class_name @class_name end |
#files ⇒ Object
Returns the value of attribute files.
8 9 10 |
# File 'lib/rbs_config/rake_task.rb', line 8 def files @files end |
#mapping ⇒ Object
Returns the value of attribute mapping.
8 9 10 |
# File 'lib/rbs_config/rake_task.rb', line 8 def mapping @mapping end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/rbs_config/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_config/rake_task.rb', line 8 def signature_root_dir @signature_root_dir end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/rbs_config/rake_task.rb', line 8 def type @type end |
Instance Method Details
#define_clean_task ⇒ Object
53 54 55 56 57 58 |
# File 'lib/rbs_config/rake_task.rb', line 53 def define_clean_task 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rbs_config/rake_task.rb', line 36 def define_generate_task desc "Generate RBS files for config gem" task "#{name}:generate" do require "rbs_config" # load RbsConfig lazily signature_root_dir.mkpath rbs = if type == :config RbsConfig::Config.generate(files: files, class_name: class_name) else RbsConfig::RailsConfig.generate(mapping: mapping) end signature_root_dir.join("#{class_name.underscore}.rbs").write(rbs) end end |
#define_setup_task ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rbs_config/rake_task.rb', line 29 def define_setup_task desc "Run all tasks of rbs_config" deps = [:"#{name}:clean", :"#{name}:generate"] task("#{name}:setup" => deps) end |