Class: Mechanic::EngineBuilder

Inherits:
Rails::PluginBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/mechanic/engine_builder.rb

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #concat_file, #download_file, #replace_in_file

Instance Method Details

#add_capybara_webkit_gemObject



21
22
23
24
# File 'lib/mechanic/engine_builder.rb', line 21

def add_capybara_webkit_gem
  inject_into_file "#{name}.gemspec", "  s.add_development_dependency 'capybara-webkit'\n",
    :before => /^end$/
end

#add_custom_gemsObject



14
15
16
17
18
19
# File 'lib/mechanic/engine_builder.rb', line 14

def add_custom_gems
  additions_path = find_in_source_paths 'gemspec_additions'
  new_gems = File.open(additions_path).read
  inject_into_file "#{name}.gemspec", "\n#{new_gems}",
    :after => /s.add_dependency "rails", "~> 3.2.8"/
end

#add_email_validatorObject



64
65
66
67
68
69
70
# File 'lib/mechanic/engine_builder.rb', line 64

def add_email_validator
  if mountable?
    copy_file 'email_validator.rb', "app/#{name}/validators/email_validator.rb"
  else
    copy_file 'email_validator.rb', 'app/validators/email_validator.rb'
  end
end

#configure_action_mailerObject



37
38
39
40
41
42
43
# File 'lib/mechanic/engine_builder.rb', line 37

def configure_action_mailer
  inside dummy_path do
    action_mailer_host 'development', "#{name}.local"
    action_mailer_host 'test', 'www.example.com'
    action_mailer_host 'production', "#{name}.com"
  end
end

#configure_capybara_webkitObject



60
61
62
# File 'lib/mechanic/engine_builder.rb', line 60

def configure_capybara_webkit
  append_file "#{dummy_path}/spec/spec_helper.rb", "\n  Capybara.javascript_driver = :webkit\n"
end

#configure_time_zoneObject



53
54
55
56
57
58
# File 'lib/mechanic/engine_builder.rb', line 53

def configure_time_zone
  time_zone_config = <<-RUBY
      config.active_record.default_timezone = :utc
  RUBY
  inject_into_class "#{dummy_path}/config/application.rb", "Application", time_zone_config
end

#create_databaseObject



31
32
33
34
35
# File 'lib/mechanic/engine_builder.rb', line 31

def create_database
  inside dummy_path do
    bundle_command 'exec rake db:create'
  end
end

#create_github_repo(repo_name) ⇒ Object



84
85
86
87
# File 'lib/mechanic/engine_builder.rb', line 84

def create_github_repo(repo_name)
  path_addition = override_path_for_tests
  run "#{path_addition} hub create #{repo_name}"
end

#generate_rspecObject



45
46
47
48
49
50
51
# File 'lib/mechanic/engine_builder.rb', line 45

def generate_rspec
  inside dummy_path do
    bundle_command 'exec rails g rspec:install'
    inject_into_file '.rspec', " --drb", :after => '--color'
    append_file "spec/spec_helper.rb", "\n  load '\#{Rails.root}/db/seeds.rb'"
  end
end

#gitignore_filesObject



76
77
78
# File 'lib/mechanic/engine_builder.rb', line 76

def gitignore_files
  concat_file 'mechanic_gitignore', '.gitignore'
end

#init_gitObject



80
81
82
# File 'lib/mechanic/engine_builder.rb', line 80

def init_git
  run 'git init'
end

#raise_delivery_errorsObject



9
10
11
12
# File 'lib/mechanic/engine_builder.rb', line 9

def raise_delivery_errors
  replace_in_file "#{dummy_path}/config/environments/development.rb",
    'raise_delivery_errors = false', 'raise_delivery_errors = true'
end

#readmeObject



5
6
7
# File 'lib/mechanic/engine_builder.rb', line 5

def readme
  template 'README.md.erb', 'README.md'
end

#setup_default_rake_taskObject



72
73
74
# File 'lib/mechanic/engine_builder.rb', line 72

def setup_default_rake_task
  append_file 'Rakefile', "task(:default).clear\ntask :default => [:spec]"
end

#use_postgres_config_templateObject



26
27
28
29
# File 'lib/mechanic/engine_builder.rb', line 26

def use_postgres_config_template
  template 'postgresql_database.yml.erb', "#{dummy_path}/config/database.yml",
    :force => true
end