Class: Rbdock::Generate
- Inherits:
-
Object
- Object
- Rbdock::Generate
- Defined in:
- lib/rbdock/generate.rb
Class Method Summary collapse
Instance Method Summary collapse
- #base_package_template ⇒ Object
- #default_template ⇒ Object
- #erubis(template_path) ⇒ Object
- #execute ⇒ Object
-
#initialize(options) ⇒ Generate
constructor
A new instance of Generate.
- #mutiple_rubies? ⇒ Boolean
- #rbenv_template ⇒ Object
- #rvm_template ⇒ Object
- #safe_write(content) ⇒ Object
Constructor Details
#initialize(options) ⇒ Generate
Returns a new instance of Generate.
11 12 13 14 15 16 17 |
# File 'lib/rbdock/generate.rb', line 11 def initialize @image = [:image] @ruby_versions = [:ruby_versions] @use_rbenv = [:use_rbenv] @use_rvm = [:use_rvm] @app_path = [:app_path] end |
Class Method Details
.ruby_versions ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 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 |
# File 'lib/rbdock/generate.rb', line 85 def self.ruby_versions [ "1.8.6-p383", "1.8.6-p420", "1.8.7-p249", "1.8.7-p302", "1.8.7-p334", "1.8.7-p352", "1.8.7-p357", "1.8.7-p358", "1.8.7-p370", "1.8.7-p371", "1.8.7-p374", "1.8.7-p375", "1.9.1-p378", "1.9.1-p430", "1.9.2-p0", "1.9.2-p180", "1.9.2-p290", "1.9.2-p318", "1.9.2-p320", "1.9.2-p326", "1.9.3-dev", "1.9.3-p0", "1.9.3-p125", "1.9.3-p194", "1.9.3-p286", "1.9.3-p327", "1.9.3-p362", "1.9.3-p374", "1.9.3-p385", "1.9.3-p392", "1.9.3-p429", "1.9.3-p448", "1.9.3-p484", "1.9.3-preview1", "1.9.3-rc1", "2.0.0-dev", "2.0.0-p0", "2.0.0-p195", "2.0.0-p247", "2.0.0-p353", "2.0.0-preview1", "2.0.0-preview2", "2.0.0-rc1", "2.0.0-rc2", "2.1.0", "2.1.0-dev", "2.1.0-preview1", "2.1.0-preview2", "2.1.0-rc1", "2.2.0-dev" ] end |
.run(options) ⇒ Object
7 8 9 |
# File 'lib/rbdock/generate.rb', line 7 def self.run new().execute end |
Instance Method Details
#base_package_template ⇒ Object
58 59 60 |
# File 'lib/rbdock/generate.rb', line 58 def base_package_template erubis Rbdock.source_root.join("templates/base_package/#{@image}.erb") end |
#default_template ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/rbdock/generate.rb', line 62 def default_template template = base_package_template template << erubis(Rbdock.source_root.join("templates/default/ruby.erb")) template << erubis(Rbdock.source_root.join("templates/default/bundler.erb")) template << erubis(Rbdock.source_root.join("templates/default/app.erb")) if @app_path template end |
#erubis(template_path) ⇒ Object
54 55 56 |
# File 'lib/rbdock/generate.rb', line 54 def erubis template_path Erubis::Eruby.new(template_path.read, trim: true).result(binding) end |
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbdock/generate.rb', line 19 def execute if @use_rbenv safe_write rbenv_template elsif @use_rvm safe_write rvm_template elsif mutiple_rubies? safe_write rbenv_template else safe_write default_template end end |
#mutiple_rubies? ⇒ Boolean
50 51 52 |
# File 'lib/rbdock/generate.rb', line 50 def mutiple_rubies? @ruby_versions.length > 1 end |
#rbenv_template ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/rbdock/generate.rb', line 70 def rbenv_template template = base_package_template template << erubis(Rbdock.source_root.join("templates/rbenv/ruby.erb")) template << erubis(Rbdock.source_root.join("templates/rbenv/bundler.erb")) template << erubis(Rbdock.source_root.join("templates/rbenv/app.erb")) if @app_path template end |
#rvm_template ⇒ Object
78 79 80 81 82 83 |
# File 'lib/rbdock/generate.rb', line 78 def rvm_template template = base_package_template template << erubis(Rbdock.source_root.join("templates/rvm/ruby.erb")) template << erubis(Rbdock.source_root.join("templates/rvm/bundler.erb")) template << erubis(Rbdock.source_root.join("templates/rvm/app.erb")) if @app_path end |
#safe_write(content) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rbdock/generate.rb', line 31 def safe_write content if File.exist? 'Dockerfile' STDERR.print "Overwrite Dockerfile? y/n: " if $stdin.gets.chomp == 'y' File.open('Dockerfile','w') do |f| f.puts content end STDERR.puts 'Dockerfile is successfully generated' else puts content end else File.open('Dockerfile','w') do |f| f.puts content end STDERR.puts 'Dockerfile is successfully generated' end end |