Class: Shuttle::Generator

Inherits:
Object
  • Object
show all
Includes:
TerminalHelpers
Defined in:
lib/shuttle/generator.rb

Constant Summary collapse

STRATEGIES =
%w(static wordpress rails)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy = 'static') ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
15
16
17
# File 'lib/shuttle/generator.rb', line 10

def initialize(strategy='static')
  unless STRATEGIES.include?(strategy)
    raise ArgumentError, "Invalid strategy: #{strategy}"
  end

  @strategy = strategy
  @path = File.join(Dir.pwd, 'shuttle.yml')
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



8
9
10
# File 'lib/shuttle/generator.rb', line 8

def git
  @git
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/shuttle/generator.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/shuttle/generator.rb', line 8

def path
  @path
end

#strategyObject (readonly)

Returns the value of attribute strategy.



7
8
9
# File 'lib/shuttle/generator.rb', line 7

def strategy
  @strategy
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shuttle/generator.rb', line 19

def run
  @name = ask('Application name', :required => true)
  @git  = ask('Git repository', :required => true)

  hash = send("generate_#{strategy}")

  File.open(path, 'w') do |f|
    f.write(YAML.dump(hash))
  end

  display "New shuttle config has been generated at ./shuttle.yml"
end