Class: TTY::Commands::New Private
- Includes:
- Licenses
- Defined in:
- lib/tty/commands/new.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The ‘new` command
Constant Summary collapse
- GEMSPEC_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Pathname(__dir__).join('../../../tty.gemspec').realpath.to_s
Constants included from Licenses
Licenses::CUSTOM, Licenses::LICENSES
Instance Attribute Summary collapse
- #app_name ⇒ Object readonly private
- #app_path ⇒ Object readonly private
- #options ⇒ Object readonly private
- #target_path ⇒ Object readonly private
- #templates ⇒ Object readonly private
Instance Method Summary collapse
- #author ⇒ Object private
- #constantinized_name ⇒ Object private
-
#execute(input: $stdin, output: $stdout) ⇒ Object
Execute the command.
- #file_options ⇒ Object private
- #gemspec_name ⇒ Object private
- #gemspec_path ⇒ Object private
- #git_author ⇒ Object private
- #git_exist? ⇒ Boolean private
-
#initialize(app_path, options) ⇒ New
constructor
private
A new instance of New.
- #namespaced_path ⇒ Object private
- #template_context ⇒ Object private
- #underscored_name ⇒ Object private
Methods included from Licenses
#license_identifiers, #licenses
Methods inherited from TTY::Cmd
#command, #constantinize, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Methods included from PathHelpers
#name_from_path, #relative_path_from, #root_path, #within_root_path
Constructor Details
#initialize(app_path, options) ⇒ New
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of New.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tty/commands/new.rb', line 39 def initialize(app_path, ) @app_path = relative_path_from(root_path, app_path) @app_name = name_from_path(app_path) = @pastel = Pastel.new(enabled: !['no-color']) @target_path = root_path.join(@app_path) @templater = Templater.new('new', @app_path) @runner = command(printer: :null) end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/tty/commands/new.rb', line 27 def app_name @app_name end |
#app_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/tty/commands/new.rb', line 29 def app_path @app_path end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/tty/commands/new.rb', line 32 def end |
#target_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/tty/commands/new.rb', line 35 def target_path @target_path end |
#templates ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/tty/commands/new.rb', line 37 def templates @templates end |
Instance Method Details
#author ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 63 64 65 66 |
# File 'lib/tty/commands/new.rb', line 58 def if !Array(['author']).empty? ['author'].join(', ') elsif !.empty? else 'TODO: Write your name' end end |
#constantinized_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/tty/commands/new.rb', line 76 def constantinized_name constantinize(app_name) end |
#execute(input: $stdin, output: $stdout) ⇒ Object
Execute the command
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/tty/commands/new.rb', line 110 def execute(input: $stdin, output: $stdout) output.puts "OPTS: #{options}" if ['debug'] coc_opt = ['coc'] ? '--coc' : '--no-coc' ext_opt = ['ext'] ? '--ext' : '--no-ext' test_opt = ['test'] command = [ "bundle gem #{target_path}", '--no-mit', '--no-exe', coc_opt, ext_opt, "-t #{test_opt}" ].join(' ') install_info = [] @runner.run(command) do |out, err| next unless out out.each_line do |line| if line =~ /^Initializing git/ install_info << line.dup next elsif line =~ /^(Gem.*?was successfully created)/ next end if !['no-color'] output.puts color_actions(line) else output.puts line end end end add_app_templates add_empty_directories add_required_libs_to_gemspec @templater.generate(template_context, ) make_executable output.puts install_info.join("\n") unless install_info.empty? output.puts "\n" + @pastel.green("Your teletype project has been created successfully.") output.puts "\n" + @pastel.green("Run \"teletype help\" for more commands.\n") end |
#file_options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
92 93 94 95 96 97 |
# File 'lib/tty/commands/new.rb', line 92 def opts = {} opts[:force] = true if ['force'] opts[:color] = false if ['no-color'] opts end |
#gemspec_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 |
# File 'lib/tty/commands/new.rb', line 99 def gemspec_name "#{app_name}.gemspec" end |
#gemspec_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 |
# File 'lib/tty/commands/new.rb', line 103 def gemspec_path target_path.join("#{app_name}.gemspec").to_s end |
#git_author ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/tty/commands/new.rb', line 54 def git_exist? ? `git config user.name`.chomp : '' end |
#git_exist? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/tty/commands/new.rb', line 50 def git_exist? exec_exist?('git') end |
#namespaced_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/tty/commands/new.rb', line 68 def namespaced_path app_name.tr('-', '/') end |
#template_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tty/commands/new.rb', line 80 def template_context opts = OpenStruct.new opts[:app_name] = app_name opts[:author] = opts[:namespaced_path] = namespaced_path opts[:underscored_name] = underscored_name opts[:constantinized_name] = constantinized_name opts[:constantinized_parts] = constantinized_name.split('::') opts[:indent] = ' ' * constantinized_name.split('::').size opts end |
#underscored_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/tty/commands/new.rb', line 72 def underscored_name app_name.tr('-', '_') end |