Class: RbsSettingslogic::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rbs_settingslogic/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/rbs_settingslogic/rake_task.rb', line 10

def name
  @name
end

#signature_root_dirObject

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_taskObject



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_taskObject



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_taskObject



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_taskObject



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