Class: Savvy::Application
- Inherits:
-
Object
- Object
- Savvy::Application
- Includes:
- Commander::Methods
- Defined in:
- lib/savvy/application.rb
Constant Summary collapse
- SAVVYFILE_TEMPLATE =
File.join(__dir__, 'templates', 'Savvyfile.rb.erb')
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#savvyfile ⇒ Object
readonly
Returns the value of attribute savvyfile.
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
- #savvyfile_contents ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/savvy/application.rb', line 10 def config @config end |
#savvyfile ⇒ Object (readonly)
Returns the value of attribute savvyfile.
11 12 13 |
# File 'lib/savvy/application.rb', line 11 def savvyfile @savvyfile end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/savvy/application.rb', line 20 def run program :name, 'savvy' program :version, Savvy::VERSION program :description, 'Savvy file generator' command :init do |c| c.syntax = 'savvy init' c.description = 'Initialize a Savvyfile' c.action do if savvyfile.exist? puts "! #{savvyfile} exists" unless agree("Do you want to overwrite? ") puts "Not overwriting" exit end end contents = savvyfile_contents puts "Writing to #{savvyfile}" savvyfile.open('w+') do |f| f.write contents end end end run! end |
#savvyfile_contents ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/savvy/application.rb', line 52 def savvyfile_contents app_name = config.app_name = ask 'What is the name of your app? ' do |q| q.default = config.app_name end ERB.new(File.read(SAVVYFILE_TEMPLATE)).result(binding) end |