rails_on_rails 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +149 -0
  3. data/bin/rails_on_rails +5 -0
  4. data/lib/autogenerators/bash_commands/generate_controller.sh +1 -0
  5. data/lib/autogenerators/bash_commands/generate_model.sh +1 -0
  6. data/lib/autogenerators/bash_commands/install_rspec.sh +1 -0
  7. data/lib/autogenerators/generator_templates/application_record.txt +8 -0
  8. data/lib/autogenerators/generator_templates/controller.txt +14 -0
  9. data/lib/autogenerators/generator_templates/test_rspec_controller.txt +169 -0
  10. data/lib/autogenerators/generator_templates/test_seeder.txt +45 -0
  11. data/lib/autogenerators/handlers/controller.rb +28 -0
  12. data/lib/autogenerators/handlers/initialize_api_docs.rb +24 -0
  13. data/lib/autogenerators/handlers/initialize_global_controller.rb +7 -0
  14. data/lib/autogenerators/handlers/initialize_rspec.rb +23 -0
  15. data/lib/autogenerators/handlers/test_rspec_controller.rb +16 -0
  16. data/lib/autogenerators/handlers/test_seeder.rb +16 -0
  17. data/lib/autogenerators/rails_templates/api_documentation.rake +181 -0
  18. data/lib/autogenerators/rails_templates/auth_helper.rb +73 -0
  19. data/lib/autogenerators/rails_templates/documentation/index.html.erb +121 -0
  20. data/lib/autogenerators/rails_templates/documentation/layout.html.erb +14 -0
  21. data/lib/autogenerators/rails_templates/documentation_controller.rb +139 -0
  22. data/lib/autogenerators/rails_templates/global_controller.rb +411 -0
  23. data/lib/autogenerators/rails_templates/seeds.rb +91 -0
  24. data/lib/constants/cli_constants.rb +56 -0
  25. data/lib/constants/options.rb +61 -0
  26. data/lib/rails_on_rails.rb +124 -0
  27. data/lib/utils/rails_methods.rb +9 -0
  28. metadata +111 -0
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Directory where all seedfiles live
4
+ # note: this is a Pathname object
5
+ def seedfiles_dir
6
+ Rails.root + 'db/seedfiles/'
7
+ end
8
+
9
+ # The main method for rails db:seed
10
+ # (called on the last line of this file)
11
+ def main
12
+ puts "Running db:seed for the #{Rails.env} environment"
13
+ run_seeds
14
+ end
15
+
16
+ # Which seedfiles should get processed when running rails db:seed
17
+ def seeds_to_run
18
+ filepaths = []
19
+ # if a filepath was passed as an argument, only run that seeder
20
+ # if ARGV.length > 1
21
+ # cmd, *seedfiles = ARGV
22
+
23
+ # set this by: rails db:seed seeds=comma_separated,file_names
24
+ if ENV['seeds']
25
+
26
+ seedfiles = ENV['seeds'].split(',')
27
+
28
+ filepaths = seedfiles.map do |str|
29
+ is_relative_path = str.split('/').length > 1
30
+ path = path = is_relative_path ? str : resolve_seeder_path
31
+
32
+ raise StandardError, "Seedfile #{path} not found" unless File.exist? path
33
+
34
+ path
35
+ end
36
+
37
+ else
38
+ # get the seedfiles which are supposed to have been run
39
+ target_seed_files = common_seedfiles + env_seedfiles
40
+
41
+ filepaths = (filepaths).concat(target_seed_files).map do |str|
42
+ resolve_seeder_path str
43
+ end
44
+
45
+ end
46
+
47
+ filepaths
48
+ end
49
+
50
+ def resolve_seeder_path(str)
51
+ common_seedfiles
52
+ .concat(env_seedfiles)
53
+ .find { |path| path.to_s.include?(str.to_s) }
54
+ end
55
+
56
+ def run_seeds
57
+ seeds_to_run.each do |path|
58
+ # check for the file
59
+ raise StandardError, "Seedfile #{s}.rb not found" unless File.exist? path
60
+
61
+ system("rails runner #{path}")
62
+ puts "Running #{path}"
63
+ end
64
+ end
65
+
66
+ # Get all seedfiles in db/seedfiles/common
67
+ def common_seedfiles
68
+ seeds_in_subfolder 'common'
69
+ end
70
+
71
+ # Get all seedfiles in the current environment's seedfile directory
72
+ def env_seedfiles
73
+ seeds_in_subfolder Rails.env
74
+ end
75
+
76
+ # Get all files within a given subfolder of seedfiles_dir
77
+ def seeds_in_subfolder(folder)
78
+ dir = seedfiles_dir + folder
79
+ # Environments aren't required to have their own directory; check first that one exists
80
+ if Dir.exist?(dir)
81
+ Dir.entries(dir).select do |fname|
82
+ fname[0] != '.' && fname.match(/\.rb$/)
83
+ end.to_a.sort.map do |fname|
84
+ seedfiles_dir + folder + fname
85
+ end
86
+ else
87
+ []
88
+ end
89
+ end
90
+
91
+ main
@@ -0,0 +1,56 @@
1
+ require_relative './options.rb'
2
+
3
+
4
+ class CLIConstants < CLIOptions
5
+ class <<self
6
+
7
+ def GEM_VERSION
8
+ gem_version
9
+ end
10
+
11
+ def CLI_DOCUMENTATION_STRING
12
+ descriptions = command_name_methods.map { |key, val| "=> #{key.to_s} - " + cli_descriptions[val] }
13
+ "#{ascii_art}
14
+ Rails on Rails Version: #{gem_version}
15
+
16
+ Rails on Rails: Command Line Interface to make your life easier.
17
+ => The Rails on Rails command is 'rails_on_rails'. To blast this project into the fifth dimension.
18
+ => Use '--help' on any of the commands listed below for more details.
19
+
20
+ List of commands:
21
+ #{descriptions.join("\n")}
22
+ "
23
+ end
24
+
25
+ def INITIALIZE_HELP_STRING
26
+ opts = skip_initialize_options.stringify_keys.keys.map { |e| "\t=> #{e}" }
27
+ "This command has no parameters but has optional commands. Optional flag options are:
28
+ --skip=<options-separated-by-a-comma-for-multiple-options>
29
+ Skip Options:
30
+ #{opts.join("\\n")}
31
+ "
32
+ end
33
+
34
+ def GENERATE_MODEL_CONTROLLER_HELP_STRING
35
+ opts = skip_model_controller_options.stringify_keys.keys.map { |e| "\t=> #{e}" }
36
+ "This command runs the same as 'rails generate model --help'.
37
+
38
+ Use the parameters in 'rails generate model' to generate your CRUD operators.
39
+ Optional flag options are:
40
+ --skip=<options-separated-by-a-comma-for-multiple-options>
41
+ Skip Options:
42
+ #{opts.join("\n")}
43
+ Use resources to declare the routes you want defined. After the generation is complete.
44
+ "
45
+ end
46
+
47
+ def GENERATE_TEST_SEEDER_HELP_STRING
48
+ "This command has one paramter which is the model name singularized in Upper Camel Case or Snake Case"
49
+ end
50
+
51
+ def GENERATE_TEST_RSPEC_HELP_STRING
52
+ "This command has one paramter which is the controller name in Upper Camel Case or Snake Case"
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ class CLIOptions
2
+ class <<self
3
+
4
+ def gem_version
5
+ "0.0.9"
6
+ end
7
+
8
+ def ascii_art
9
+ "
10
+ ________ ________ ___ ___ ________ ________ ________ ________ ________ ___ ___ ________
11
+ |\\ __ \\|\\ __ \\|\\ \\|\\ \\ |\\ ____\\ |\\ __ \\|\\ ___ \\ |\\ __ \\|\\ __ \\|\\ \\|\\ \\ |\\ ____\\
12
+ \\ \\ \\|\\ \\ \\ \\|\\ \\ \\ \\ \\ \\ \\ \\ \\___|_ \\ \\ \\|\\ \\ \\ \\\\ \\ \\ \\ \\ \\|\\ \\ \\ \\|\\ \\ \\ \\ \\ \\ \\ \\ \\___|_
13
+ \\ \\ _ _\\ \\ __ \\ \\ \\ \\ \\ \\ \\_____ \\ \\ \\ \\\\\\ \\ \\ \\\\ \\ \\ \\ \\ _ _\\ \\ __ \\ \\ \\ \\ \\ \\ \\_____ \\
14
+ \\ \\ \\\\ \\\\ \\ \\ \\ \\ \\ \\ \\ \\____\\|____|\\ \\ \\ \\ \\\\\\ \\ \\ \\\\ \\ \\ \\ \\ \\\\ \\\\ \\ \\ \\ \\ \\ \\ \\ \\____\\|____|\\ \\
15
+ \\ \\__\\\\ _\\\\ \\__\\ \\__\\ \\__\\ \\_______\\____\\_\\ \\ \\ \\_______\\ \\__\\\\ \\__\\ \\ \\__\\\\ _\\\\ \\__\\ \\__\\ \\__\\ \\_______\\____\\_\\ \\
16
+ \\|__|\\|__|\\|__|\\|__|\\|__|\\|_______|\\_________\\ \\|_______|\\|__| \\|__| \\|__|\\|__|\\|__|\\|__|\\|__|\\|_______|\\_________\\
17
+ \\|_________| \\|_________|
18
+ "
19
+ end
20
+
21
+ def skip_initialize_options
22
+ {
23
+ test: [:initialize_rspec],
24
+ rspec: [:initialize_rspec],
25
+ }
26
+ end
27
+
28
+ def skip_model_controller_options
29
+ {
30
+ test: [:generate_test_seeder, :generate_test_rspec],
31
+ }
32
+ end
33
+
34
+ def help_flags
35
+ {
36
+ :"--help" => true,
37
+ :"-h" => true,
38
+ }
39
+ end
40
+
41
+ def command_name_methods
42
+ {
43
+ i: :initialize,
44
+ init: :initialize,
45
+ model: :generate_model_and_controller,
46
+ :"test:seeder" => :generate_test_seeder,
47
+ :"test:spec" => :generate_test_rspec,
48
+ }
49
+ end
50
+
51
+ def cli_descriptions
52
+ {
53
+ initialize: 'Setup your initial Rails on Rails project',
54
+ generate_model_and_controller: 'Generate a new model migration, fully operational controller, and unit tests for that controller',
55
+ generate_test_seeder: 'Generate a test seeder for your model',
56
+ generate_test_rspec: 'Generate a test spec for your controller',
57
+ }
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,124 @@
1
+ require_relative "./constants/cli_constants.rb"
2
+ require_relative "./constants/options.rb"
3
+ require_relative "./utils/rails_methods.rb"
4
+
5
+ class Commander < CLIOptions
6
+ class <<self
7
+
8
+ def actions actions
9
+ return cli_documentation if actions.length <= 0
10
+ action_name = actions[0]
11
+ is_help = actions.select { |e| help_flags[e.to_sym] }.length > 0
12
+ options = actions.select { |e| !help_flags[e.to_sym] && !(e =~ /--/).nil? }.each_with_object({}) do |e, acc|
13
+ empty, string = e.split('--')
14
+ key, val = string.split('=')
15
+ acc[key.to_sym] = val
16
+ acc
17
+ end
18
+ method_name = action_name ? command_name_methods[action_name.to_sym] : false
19
+ arguments = [is_help, options].concat(actions[1..-1])
20
+ if method_name
21
+ method(method_name).call(*arguments)
22
+ else
23
+ cli_documentation
24
+ end
25
+ end
26
+
27
+ def cli_documentation
28
+ puts CLIConstants.CLI_DOCUMENTATION_STRING
29
+ end
30
+
31
+ def initialize *args
32
+ is_help = args[0]
33
+ options = args[1]
34
+ arguments = args[2..-1]
35
+ if is_help
36
+ puts CLIConstants.INITIALIZE_HELP_STRING
37
+ else
38
+ puts "Initializing Rails on Rails..."
39
+ all_initial_methods = [:initialize_rspec, :initialize_api_documentation, :initialize_model_and_controller]
40
+ skip_options = options[:skip]
41
+ skipping = {}
42
+ if skip_options
43
+ skipping = skip_options.split(',').flat_map { |e| skip_initialize_options[e.to_sym] }.select { |e| e.nil? == false }.each_with_object({}) do |e, acc|
44
+ acc[e] = true
45
+ acc
46
+ end
47
+ end
48
+ all_initial_methods = all_initial_methods.reject { |e| skipping[e].nil? == false }
49
+ all_initial_methods.map { |e| e.to_sym }.each { |e| method(e).call }
50
+ puts "Rails on Rails has been initialize"
51
+ end
52
+ end
53
+
54
+ def initialize_api_documentation
55
+ path = __dir__ + '/autogenerators/handlers/initialize_api_docs.rb'
56
+ system("ruby #{path}")
57
+ end
58
+
59
+ def initialize_model_and_controller
60
+ path = __dir__ + '/autogenerators/handlers/initialize_global_controller.rb'
61
+ system("ruby #{path}")
62
+ end
63
+
64
+ def initialize_rspec *args
65
+ path = __dir__ + '/autogenerators/handlers/initialize_rspec.rb'
66
+ system("ruby #{path}")
67
+ end
68
+
69
+ def generate_model_and_controller *args
70
+ is_help = args[0]
71
+ options = args[1]
72
+ arguments = args[2..-1]
73
+ if is_help
74
+ puts CLIConstants.GENERATE_MODEL_CONTROLLER_HELP_STRING
75
+ else
76
+ puts "Generating model and controller for #{args[2]}..."
77
+ all_action_methods = [:generate_test_seeder, :generate_test_rspec]
78
+ skip_options = options[:skip]
79
+ skipping = {}
80
+ if skip_options
81
+ 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|
82
+ acc[e] = true
83
+ acc
84
+ end
85
+ end
86
+ all_action_methods = all_action_methods.reject { |e| skipping[e].nil? == false }
87
+ path = __dir__ + '/autogenerators/handlers/controller.rb'
88
+ system("ruby #{path} #{arguments.join(' ')}")
89
+ all_action_methods.each { |e| method(e).call(*args) }
90
+ puts "Finished generating model and controller for #{args[2]}"
91
+ end
92
+ end
93
+
94
+ def generate_test_seeder *args
95
+ is_help = args[0]
96
+ options = args[1]
97
+ arguments = args[2..-1]
98
+ if is_help
99
+ puts CLIConstants.GENERATE_TEST_SEEDER_HELP_STRING
100
+ else
101
+ puts "Generating test seeder for #{args[2]}..."
102
+ path = __dir__ + '/autogenerators/handlers/test_seeder.rb'
103
+ system("ruby #{path} #{arguments.join(' ')}")
104
+ puts "Finished generating test seeder for #{args[2]}"
105
+ end
106
+ end
107
+
108
+ def generate_test_rspec *args
109
+ is_help = args[0]
110
+ options = args[1]
111
+ arguments = args[2..-1]
112
+ if is_help
113
+ puts CLIConstants.GENERATE_TEST_RSPEC_HELP_STRING
114
+ else
115
+ puts "Generating test spec for #{args[2]}..."
116
+ path = __dir__ + '/autogenerators/handlers/test_rspec_controller.rb'
117
+ system("ruby #{path} #{arguments.join(' ')}")
118
+ puts "Finished generating test spec for #{args[2]}"
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+
@@ -0,0 +1,9 @@
1
+ class String
2
+ def underscore
3
+ self.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ tr("-", "_").
7
+ downcase
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Aidan Miles
8
+ - Layne Faler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec-rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.8'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.8'
42
+ - !ruby/object:Gem::Dependency
43
+ name: faker
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.9'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.9'
56
+ description: A scaffolding tool for your Rails projects
57
+ email: lfaler@appliedvr.to
58
+ executables:
59
+ - rails_on_rails
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - bin/rails_on_rails
65
+ - lib/autogenerators/bash_commands/generate_controller.sh
66
+ - lib/autogenerators/bash_commands/generate_model.sh
67
+ - lib/autogenerators/bash_commands/install_rspec.sh
68
+ - lib/autogenerators/generator_templates/application_record.txt
69
+ - lib/autogenerators/generator_templates/controller.txt
70
+ - lib/autogenerators/generator_templates/test_rspec_controller.txt
71
+ - lib/autogenerators/generator_templates/test_seeder.txt
72
+ - lib/autogenerators/handlers/controller.rb
73
+ - lib/autogenerators/handlers/initialize_api_docs.rb
74
+ - lib/autogenerators/handlers/initialize_global_controller.rb
75
+ - lib/autogenerators/handlers/initialize_rspec.rb
76
+ - lib/autogenerators/handlers/test_rspec_controller.rb
77
+ - lib/autogenerators/handlers/test_seeder.rb
78
+ - lib/autogenerators/rails_templates/api_documentation.rake
79
+ - lib/autogenerators/rails_templates/auth_helper.rb
80
+ - lib/autogenerators/rails_templates/documentation/index.html.erb
81
+ - lib/autogenerators/rails_templates/documentation/layout.html.erb
82
+ - lib/autogenerators/rails_templates/documentation_controller.rb
83
+ - lib/autogenerators/rails_templates/global_controller.rb
84
+ - lib/autogenerators/rails_templates/seeds.rb
85
+ - lib/constants/cli_constants.rb
86
+ - lib/constants/options.rb
87
+ - lib/rails_on_rails.rb
88
+ - lib/utils/rails_methods.rb
89
+ homepage: https://bitbucket.org/appliedvrdev/rails/src/master
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.4.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.0.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A scaffolding tool for your Rails projects!
111
+ test_files: []