Module: Jets::CLI::Group::Actions
Instance Method Summary collapse
- #comment_out_line(string, options = {}) ⇒ Object
- #config_environment(data, options = {}) ⇒ Object
- #environment(data = nil, options = {}) ⇒ Object (also: #application)
-
#optimize_indentation(value, amount = 0) ⇒ Object
(also: #rebase_indentation)
:doc:.
Instance Method Details
#comment_out_line(string, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jets/cli/group/actions.rb', line 41 def comment_out_line(string, = {}) file = if [:env] "config/environments/#{[:env]}.rb" else "config/application.rb" end lines = IO.readlines(file).map do |l| if l.include?(string) && !l.strip.start_with?("#") " # #{l.strip}" else l end end IO.write(file, lines.join) end |
#config_environment(data, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jets/cli/group/actions.rb', line 5 def config_environment(data, = {}) config_file = if [:env] "config/environments/#{[:env]}.rb" else "config/application.rb" end lines = IO.readlines(config_file) # remove comment lines lines.reject! { |line| line =~ /^\s*#/ } found = lines.any? { |line| line.include?(data) } environment(data, ) unless found end |
#environment(data = nil, options = {}) ⇒ Object Also known as: application
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jets/cli/group/actions.rb', line 18 def environment(data = nil, = {}) sentinel = "class Application < Rails::Application\n" env_file_sentinel = "Rails.application.configure do\n" data ||= yield if block_given? in_root do if [:env].nil? inject_into_file "config/application.rb", optimize_indentation(data, 4), after: sentinel, verbose: true else Array([:env]).each do |env| inject_into_file "config/environments/#{env}.rb", optimize_indentation(data, 2), after: env_file_sentinel, verbose: true end end end end |
#optimize_indentation(value, amount = 0) ⇒ Object Also known as: rebase_indentation
:doc:
35 36 37 38 |
# File 'lib/jets/cli/group/actions.rb', line 35 def optimize_indentation(value, amount = 0) # :doc: return "#{value}\n" unless value.is_a?(String) "#{value.strip_heredoc.indent(amount).chomp}\n" end |