Class: Cassie::Configuration::Generator

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/cassie/configuration/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Generator

Returns a new instance of Generator.



11
12
13
14
15
# File 'lib/cassie/configuration/generator.rb', line 11

def initialize(opts={})
  @app_name = opts.fetch(:app_name, default_app_name)
  @template_path = opts.fetch(:template_path, default_template_path)
  @destination_path = opts.fetch(:destination_path, default_destination_path)
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



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

def app_name
  @app_name
end

#destination_pathObject

Returns the value of attribute destination_path.



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

def destination_path
  @destination_path
end

#template_pathObject

Returns the value of attribute template_path.



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

def template_path
  @template_path
end

Instance Method Details

#renderObject



17
18
19
# File 'lib/cassie/configuration/generator.rb', line 17

def render
  ERB.new(template).result(binding)
end

#saveObject



21
22
23
24
25
26
# File 'lib/cassie/configuration/generator.rb', line 21

def save
  raise "#{destination_path} already exists" if File.exists?(destination_path)
  File.open(destination_path, "w+") do |f|
    f.write(render)
  end
end