Class: RbsHeuristicPrototype::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RbsHeuristicPrototype::RakeTask
- Defined in:
- lib/rbs_heuristic_prototype/rake_task.rb
Constant Summary collapse
- FILTERS =
{ action_mailer: "RbsHeuristicPrototype::Filters::ActionMailerFilter", active_model_validations: "RbsHeuristicPrototype::Filters::ActiveModelValidationsFilter", boolean_methods: "RbsHeuristicPrototype::Filters::BooleanMethodsFilter", deep_module: "RbsHeuristicPrototype::Filters::DeepModuleFilter", rails_concerns: "RbsHeuristicPrototype::Filters::RailsConcernsFilter", # rails_helpers: "RbsHeuristicPrototype::Filters::RailsHelpersFilter", symbol_array_constants: "RbsHeuristicPrototype::Filters::SymbolArrayConstantsFilter", type_args: "RbsHeuristicPrototype::Filters::TypeArgsFilter" }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #define_apply_task ⇒ Object
- #define_setup_task ⇒ Object
-
#initialize(name = :"rbs:prototype:heuristic", &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
- #load_env(path) ⇒ Object
- #write_env(path, env) ⇒ Object
Constructor Details
#initialize(name = :"rbs:prototype:heuristic", &block) ⇒ RakeTask
Returns a new instance of RakeTask.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 23 def initialize(name = :"rbs:prototype:heuristic", &block) super() @name = name @path = Pathname(Rails.root / "sig/prototype") block&.call(self) define_apply_task define_setup_task end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 21 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 21 def path @path end |
Instance Method Details
#define_apply_task ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 42 def define_apply_task desc "Apply heuristic filters to prototype signatures" task("#{name}:apply": :environment) do require "rbs_heuristic_prototype" # load RbsHeuristicPrototype lazily Parallel.each(path.find) do |entry| next unless entry.file? env = FILTERS.inject(load_env(entry)) do |result, (_name, filter)| filter.constantize.new(result).apply end write_env(entry, env) end end end |
#define_setup_task ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 35 def define_setup_task desc "Run all tasks of rbs_heuristic_prototype" deps = [:"#{name}:apply"] task("#{name}:setup": deps) end |
#load_env(path) ⇒ Object
59 60 61 62 63 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 59 def load_env(path) loader = RBS::EnvironmentLoader.new(core_root: nil) loader.add(path: path) RBS::Environment.from_loader(loader) end |
#write_env(path, env) ⇒ Object
65 66 67 68 69 |
# File 'lib/rbs_heuristic_prototype/rake_task.rb', line 65 def write_env(path, env) path.open("wt") do |out| RBS::Writer.new(out: out).write(env.declarations) end end |