Class: Savvy::Application

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



13
14
15
16
17
18
# File 'lib/savvy/application.rb', line 13

def initialize
  @config = Savvy.config
  @savvyfile = Savvy.config.root.join('Savvyfile')

  @config.setup!
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/savvy/application.rb', line 10

def config
  @config
end

#savvyfileObject (readonly)

Returns the value of attribute savvyfile.



11
12
13
# File 'lib/savvy/application.rb', line 11

def savvyfile
  @savvyfile
end

Instance Method Details

#runObject



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_contentsObject



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