Class: Gemsmith::Skeletons::RailsSkeleton

Inherits:
BaseSkeleton show all
Defined in:
lib/gemsmith/skeletons/rails_skeleton.rb

Overview

Configures Ruby on Rails support.

Instance Method Summary collapse

Methods inherited from BaseSkeleton

create, #initialize

Constructor Details

This class inherits a constructor from Gemsmith::Skeletons::BaseSkeleton

Instance Method Details

#createObject



38
39
40
41
42
43
44
# File 'lib/gemsmith/skeletons/rails_skeleton.rb', line 38

def create
  return unless enabled? && rails?

  create_engine
  create_generator_files
  create_travis_gemfiles
end

#create_engineObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gemsmith/skeletons/rails_skeleton.rb', line 13

def create_engine
  cli.template "#{lib_root}/%gem_name%/engine.rb.tt", cli.template_options

  gem_name = cli.template_options.fetch :gem_name
  system "rails plugin new --skip #{gem_name} #{engine_options}"

  cli.remove_file "#{gem_name}/app/helpers/#{gem_name}/application_helper.rb", cli.template_options
  cli.remove_file "#{gem_name}/lib/#{gem_name}/version.rb", cli.template_options
  cli.remove_file "#{gem_name}/MIT-LICENSE", cli.template_options
  cli.remove_file "#{gem_name}/README.rdoc", cli.template_options
end

#create_generator_filesObject



25
26
27
28
29
30
31
# File 'lib/gemsmith/skeletons/rails_skeleton.rb', line 25

def create_generator_files
  cli.empty_directory "#{generator_root}/templates"
  cli.template "#{generator_root}/install/install_generator.rb.tt", cli.template_options
  cli.template "#{generator_root}/install/USAGE.tt", cli.template_options
  cli.template "#{generator_root}/upgrade/upgrade_generator.rb.tt", cli.template_options
  cli.template "#{generator_root}/upgrade/USAGE.tt", cli.template_options
end

#create_travis_gemfilesObject



33
34
35
36
# File 'lib/gemsmith/skeletons/rails_skeleton.rb', line 33

def create_travis_gemfiles
  return unless cli.template_options[:travis]
  cli.template "%gem_name%/gemfiles/rails-4.1.x.gemfile.tt", cli.template_options
end

#enabled?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/gemsmith/skeletons/rails_skeleton.rb', line 5

def enabled?
  cli.template_options.key?(:rails) && cli.template_options[:rails]
end

#rails?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/gemsmith/skeletons/rails_skeleton.rb', line 9

def rails?
  system "command -v rails"
end