Class: Commander

Inherits:
CLIOptions show all
Defined in:
lib/rails_on_rails.rb

Class Method Summary collapse

Methods inherited from CLIOptions

ascii_art, cli_descriptions, command_name_methods, gem_version, help_flags, skip_initialize_options, skip_model_controller_options

Class Method Details

.actions(actions) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_on_rails.rb', line 8

def actions actions
    return cli_documentation if actions.length <= 0
    action_name = actions[0]
    is_help = actions.select { |e| help_flags[e.to_sym] }.length > 0
    options = actions.select { |e| !help_flags[e.to_sym] && !(e =~ /--/).nil? }.each_with_object({}) do |e, acc|
        empty, string = e.split('--')
        key, val = string.split('=')
        acc[key.to_sym] = val
        acc
    end 
    method_name = action_name ? command_name_methods[action_name.to_sym] : false
    arguments = [is_help, options].concat(actions[1..-1])
    if method_name
        method(method_name).call(*arguments)
    else
        cli_documentation
    end
end

.cli_documentationObject



27
28
29
# File 'lib/rails_on_rails.rb', line 27

def cli_documentation
    puts CLIConstants.CLI_DOCUMENTATION_STRING
end

.generate_model_and_controller(*args) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rails_on_rails.rb', line 69

def generate_model_and_controller *args
    is_help = args[0]
    options = args[1]
    arguments = args[2..-1]
    if is_help
        puts CLIConstants.GENERATE_MODEL_CONTROLLER_HELP_STRING
    else 
        puts "Generating model and controller for #{args[2]}..."
        all_action_methods = [:generate_test_seeder, :generate_test_rspec]
        skip_options = options[:skip]
        no_model = !options[:"no-model"].nil?
        v2 = !options[:"v2"].nil?
        skipping = {}
        if skip_options
            skipping = skip_options.split(',').flat_map { |e| skip_model_controller_options[e.to_sym] }.select { |e| e.nil? == false }.each_with_object({}) do |e, acc|
                acc[e] = true
                acc
            end
        end
        all_action_methods = all_action_methods.reject { |e| skipping[e].nil? == false }
        path = __dir__ + '/autogenerators/handlers/controller.rb'
        system("ruby #{path} #{no_model} #{v2} #{arguments.join(' ')}")
        all_action_methods.each { |e| method(e).call(*args) }
        puts "Finished generating model and controller for #{args[2]}"
    end
end

.generate_test_rspec(*args) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rails_on_rails.rb', line 110

def generate_test_rspec *args
    is_help = args[0]
    options = args[1]
    arguments = args[2..-1]
    if is_help
        puts CLIConstants.GENERATE_TEST_RSPEC_HELP_STRING
    else 
        puts "Generating test spec for #{args[2]}..."
        path = __dir__ + '/autogenerators/handlers/test_rspec_controller.rb'
        system("ruby #{path} #{arguments.join(' ')}")
        puts "Finished generating test spec for #{args[2]}"
    end
end

.generate_test_seeder(*args) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rails_on_rails.rb', line 96

def generate_test_seeder *args
    is_help = args[0]
    options = args[1]
    arguments = args[2..-1]
    if is_help
        puts CLIConstants.GENERATE_TEST_SEEDER_HELP_STRING
    else 
        puts "Generating test seeder for #{args[2]}..."
        path = __dir__ + '/autogenerators/handlers/test_seeder.rb'
        system("ruby #{path} #{arguments.join(' ')}")
        puts "Finished generating test seeder for #{args[2]}"
    end
end

.initialize(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_on_rails.rb', line 31

def initialize *args
    is_help = args[0]
    options = args[1]
    arguments = args[2..-1]
    if is_help
        puts CLIConstants.INITIALIZE_HELP_STRING
    else 
        puts "Initializing Rails on Rails..."
        all_initial_methods = [:initialize_rspec, :initialize_api_documentation, :initialize_model_and_controller]
        skip_options = options[:skip]
        skipping = {}
        if skip_options
            skipping = skip_options.split(',').flat_map { |e| skip_initialize_options[e.to_sym] }.select { |e| e.nil? == false }.each_with_object({}) do |e, acc|
                acc[e] = true
                acc
            end
        end
        all_initial_methods = all_initial_methods.reject { |e| skipping[e].nil? == false }
        all_initial_methods.map { |e| e.to_sym }.each { |e| method(e).call }
        puts "Rails on Rails has been initialize"
    end
end

.initialize_api_documentationObject



54
55
56
57
# File 'lib/rails_on_rails.rb', line 54

def initialize_api_documentation
    path = __dir__ + '/autogenerators/handlers/initialize_api_docs.rb'
    system("ruby #{path}")
end

.initialize_model_and_controllerObject



59
60
61
62
# File 'lib/rails_on_rails.rb', line 59

def initialize_model_and_controller
    path = __dir__ + '/autogenerators/handlers/initialize_global_controller.rb'
    system("ruby #{path}")
end

.initialize_rspec(*args) ⇒ Object



64
65
66
67
# File 'lib/rails_on_rails.rb', line 64

def initialize_rspec *args
    path = __dir__ + '/autogenerators/handlers/initialize_rspec.rb'
    system("ruby #{path}")
end