Class: Dummier::AppGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Dummier::AppGenerator
- Defined in:
- lib/dummier/app_generator.rb
Instance Method Summary collapse
-
#application_definition ⇒ Object
(also: #store_application_definition!)
gets the current application.rb contents.
-
#camelized ⇒ Object
The name, camelized.
-
#defaults ⇒ Object
Default generator options.
-
#destination_path ⇒ Object
Path to the testing application.
-
#extension ⇒ Object
The name of the extension to be tested.
-
#fire_hook(hook_name) ⇒ Object
Loads a hook file and evalutes its contents.
-
#initialize(root, options = {}) ⇒ AppGenerator
constructor
A new instance of AppGenerator.
-
#name ⇒ Object
The name of the rails application.
-
#root_path ⇒ Object
Path the the extension’s root folder.
-
#run! ⇒ Object
Runs the generator.
-
#test_path ⇒ Object
Path to the extension’s test folder.
-
#underscored ⇒ Object
The name, underscored.
Constructor Details
#initialize(root, options = {}) ⇒ AppGenerator
Returns a new instance of AppGenerator.
19 20 21 22 23 24 25 26 27 |
# File 'lib/dummier/app_generator.rb', line 19 def initialize(root, ={}) @behavior = :invoke @root_path = File.(root) @destination_stack = [] @options = defaults.merge() self.source_paths << File.join(root_path, "test/dummy_hooks/templates") self.destination_root = File.join(test_path, name) raise "Invalid directory!" unless File.directory?(@root_path) end |
Instance Method Details
#application_definition ⇒ Object Also known as: store_application_definition!
gets the current application.rb contents
65 66 67 68 69 70 |
# File 'lib/dummier/app_generator.rb', line 65 def application_definition @application_definition ||= begin contents = File.read("#{destination_root}/config/application.rb") contents[(contents.index("module Dummy"))..-1] end end |
#camelized ⇒ Object
The name, camelized
40 41 42 |
# File 'lib/dummier/app_generator.rb', line 40 def camelized @camelized ||= name.camelize end |
#defaults ⇒ Object
Default generator options
15 16 17 |
# File 'lib/dummier/app_generator.rb', line 15 def defaults { :verbose => false } end |
#destination_path ⇒ Object
Path to the testing application
60 61 62 |
# File 'lib/dummier/app_generator.rb', line 60 def destination_path File.join(test_path, name) end |
#extension ⇒ Object
The name of the extension to be tested
35 36 37 |
# File 'lib/dummier/app_generator.rb', line 35 def extension File.basename(root_path) end |
#fire_hook(hook_name) ⇒ Object
Loads a hook file and evalutes its contents. rescues any exceptions and logs their message. Store hooks in gem_root/test/dummy_hooks
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dummier/app_generator.rb', line 76 def fire_hook(hook_name) begin file = File.join(root_path, "test/dummy_hooks/#{hook_name}.rb") say_status "hook", hook_name, File.exists?(file) ? :cyan : :red eval File.read(file) if File.exists?(file) rescue Exception => e say_status "failed", "#{hook_name} raised an exception", :red say "*" * 60, :red say e..strip + "\n", :red say e.backtrace.join("\n"), :red raise ::Dummier::HookException, "Quitting, #{hook_name} raised an exception." end end |
#name ⇒ Object
The name of the rails application
30 31 32 |
# File 'lib/dummier/app_generator.rb', line 30 def name "dummy" end |
#root_path ⇒ Object
Path the the extension’s root folder
50 51 52 |
# File 'lib/dummier/app_generator.rb', line 50 def root_path @root_path end |
#run! ⇒ Object
Runs the generator
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/dummier/app_generator.rb', line 91 def run! fire_hook :before_delete remove_existing_dummy fire_hook :before_app_generator run_base_generator fire_hook :after_app_generator inside destination_path do remove_unnecessary_files replace_boot_templates add_cucumber_support if has_features? fire_hook :before_migrate run_migration fire_hook :after_migrate end end |
#test_path ⇒ Object
Path to the extension’s test folder
55 56 57 |
# File 'lib/dummier/app_generator.rb', line 55 def test_path File.join(root_path, "test") end |
#underscored ⇒ Object
The name, underscored
45 46 47 |
# File 'lib/dummier/app_generator.rb', line 45 def underscored @underscored ||= name.underscore end |