Class: TheLocal::Generators::ProviderGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/the_local/provider_generator.rb

Constant Summary collapse

GEMFILE_LINE =
%(gem "the_local")
RAKEFILE_REQUIRE =
%(require "the_local/rake")

Instance Method Summary collapse

Instance Method Details

#add_to_gemfileObject



24
25
26
27
28
29
30
31
32
# File 'lib/generators/the_local/provider_generator.rb', line 24

def add_to_gemfile
  return if gem_name == "the_local"

  gemfile = File.join(destination_root, "Gemfile")
  return unless File.exist?(gemfile)
  return if File.read(gemfile).include?(GEMFILE_LINE)

  append_to_file "Gemfile", "\n#{GEMFILE_LINE}\n"
end

#announce_next_stepObject



19
20
21
22
# File 'lib/generators/the_local/provider_generator.rb', line 19

def announce_next_step
  say "Declare this gem's public interface in the_local/interface.yml, then " \
      "run `rake the_local:author` to write its locals into the_local/agents/."
end

#hook_check_task_into_rakefileObject



34
35
36
37
38
39
# File 'lib/generators/the_local/provider_generator.rb', line 34

def hook_check_task_into_rakefile
  return unless File.exist?(File.join(destination_root, "Rakefile"))
  return if File.read(File.join(destination_root, "Rakefile")).include?(RAKEFILE_REQUIRE)

  append_to_file "Rakefile", "\n#{RAKEFILE_REQUIRE}\n"
end

#relocate_to_gem_rootObject



15
16
17
# File 'lib/generators/the_local/provider_generator.rb', line 15

def relocate_to_gem_root
  self.destination_root = gem_root
end