3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/myrails/modules/engine_generators.rb', line 3
def self.included(thor)
thor.class_eval do
desc 'engine <OPTION> <NAME>', 'Execute without options to see HELP. Generate and configure a rails engine'
def engine(*opts)
item = opts[0]
file = Dir['*.gemspec'].first
@name = if file
File.basename(file, '.gemspec')
else
opts[1]
end
option = {
auto_setup: 'Run all of the setup options listed',
engine_setup: 'Generate default configuration in Rails::Engine. Requires the name of the engine as the argument',
gemspec_setup: 'Setup gempsec file with default information',
new: 'Generate clean a full or mountable rails gem',
rake_setup: 'Setup rake to run rspec as the default test framework along with other configs',
rspec_setup: 'Configure RSpec to work with a rails engine'
}
unless item
say 'ERROR: "myrails engine" was called with no arguments'
say 'Usage: "myrails engine <OPTION> <NAME>"'
say "Available Options:\n"
option.each{|k,v| say "* #{k}: #{v}"}
exit
end
raise ArgumentError, "NAME must be specified for #{item} option. Ex: `myrails engine <OPTION> <NAME>`" unless @name
case item
when 'auto_setup'
auto_setup
when 'engine_setup'
engine_setup
when 'gem_setup'
gem_setup
when 'gemspec_setup'
gemspec_setup
when 'new'
new_engine
when 'rake_setup'
rake_setup
when 'rspec_setup'
rspec_setup
else
say "Unknown Action! #{@name}"
end
end
desc 'e', 'Engine shortcut'
alias_method :e, :engine
end
end
|