Class: Perennial::Generator
Defined Under Namespace
Classes: CommandEnv
Instance Attribute Summary collapse
-
#destination_path ⇒ Object
Returns the value of attribute destination_path.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
- #chmod(permissions, path) ⇒ Object
- #directory?(path) ⇒ Boolean (also: #folder?)
- #download(from, to, append = false) ⇒ Object
- #executable?(path) ⇒ Boolean
- #exists?(path) ⇒ Boolean
- #file(name, contents, append = false) ⇒ Object
- #file?(path) ⇒ Boolean
- #folders(*args) ⇒ Object
-
#fu ⇒ Object
Helpers for testing file state.
-
#initialize(destination, opts = {}) ⇒ Generator
constructor
A new instance of Generator.
- #template(source, destination, environment = {}, append = false) ⇒ Object
Constructor Details
#initialize(destination, opts = {}) ⇒ Generator
Returns a new instance of Generator.
33 34 35 36 37 38 |
# File 'lib/perennial/generator.rb', line 33 def initialize(destination, opts = {}) @destination_path = destination @template_path = opts[:template_path] || File.join(Settings.library_root, "templates") @silent = !!opts[:silent] describe "Initializing generator in #{destination}" end |
Instance Attribute Details
#destination_path ⇒ Object
Returns the value of attribute destination_path.
31 32 33 |
# File 'lib/perennial/generator.rb', line 31 def destination_path @destination_path end |
#template_path ⇒ Object
Returns the value of attribute template_path.
31 32 33 |
# File 'lib/perennial/generator.rb', line 31 def template_path @template_path end |
Instance Method Details
#chmod(permissions, path) ⇒ Object
46 47 48 49 |
# File 'lib/perennial/generator.rb', line 46 def chmod(, path) describe "Changing permissions for #{path} to #{permissions}" FileUtils.chmod(, (path)) end |
#directory?(path) ⇒ Boolean Also known as: folder?
61 62 63 64 |
# File 'lib/perennial/generator.rb', line 61 def directory?(path) describe "Checking if #{path} is a directory" File.directory?((path)) end |
#download(from, to, append = false) ⇒ Object
73 74 75 76 |
# File 'lib/perennial/generator.rb', line 73 def download(from, to, append = false) describe "Downloading #{from}" file to, open(from).read, append end |
#executable?(path) ⇒ Boolean
56 57 58 59 |
# File 'lib/perennial/generator.rb', line 56 def executable?(path) describe "Checking if #{path} is an executable" File.executable?((path)) end |
#exists?(path) ⇒ Boolean
68 69 70 71 |
# File 'lib/perennial/generator.rb', line 68 def exists?(path) describe "Checking if #{path} exists" File.exits?((path)) end |
#file(name, contents, append = false) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/perennial/generator.rb', line 85 def file(name, contents, append = false) dest_folder = File.dirname(name) folders(dest_folder) unless File.directory?((dest_folder)) describe "Creating file #{name}" File.open((name), "#{append ? "a" : "w"}+") do |f| f.write(contents) end end |
#file?(path) ⇒ Boolean
51 52 53 54 |
# File 'lib/perennial/generator.rb', line 51 def file?(path) describe "Checking if #{path} is a file" File.file?((path)) end |
#folders(*args) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/perennial/generator.rb', line 78 def folders(*args) args.each do |f| describe "Creating folder #{f}" FileUtils.mkdir_p((f)) end end |
#fu ⇒ Object
Helpers for testing file state
42 43 44 |
# File 'lib/perennial/generator.rb', line 42 def fu FileUtils end |
#template(source, destination, environment = {}, append = false) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/perennial/generator.rb', line 94 def template(source, destination, environment = {}, append = false) describe "Processing template #{source}" raw_template = File.read((source)) processed_template = ERB.new(raw_template).result(binding_for(environment)) file destination, processed_template, append end |