class Cassie::Configuration::Generator
Attributes
app_name[RW]
destination_path[RW]
template_path[RW]
Public Class Methods
new(opts={})
click to toggle source
# 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
Public Instance Methods
render()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 17 def render ERB.new(template).result(binding) end
save()
click to toggle source
# 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
Protected Instance Methods
config_dir()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 47 def config_dir File.join(root, "config") end
default_app_name()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 34 def default_app_name "my_app" end
default_destination_path()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 42 def default_destination_path Dir.mkdir(config_dir) unless File.directory?(config_dir) File.join(root, "config/cassandra.yml") end
default_template_path()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 38 def default_template_path File.expand_path("../templates/cassandra.yml", __FILE__) end
root()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 51 def root Dir.pwd end
template()
click to toggle source
# File lib/cassie/configuration/generator.rb, line 30 def template File.new(template_path).read end