Class: Cear::File
- Inherits:
-
Object
- Object
- Cear::File
- Defined in:
- lib/cear/file.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_gems(condition, gems) ⇒ Object
- #file_generator(file, path = '../../template') ⇒ Object
- #generate_file(filename, options = {}) ⇒ Object
-
#initialize(__app_name, options = {}) ⇒ File
constructor
A new instance of File.
- #run ⇒ Object
- #template_exists?(file, path = '../../template') ⇒ Boolean
Constructor Details
#initialize(__app_name, options = {}) ⇒ File
Returns a new instance of File.
10 11 12 13 |
# File 'lib/cear/file.rb', line 10 def initialize(__app_name, = {}) @app_name = __app_name @options = end |
Class Method Details
Instance Method Details
#add_gems(condition, gems) ⇒ Object
23 24 25 |
# File 'lib/cear/file.rb', line 23 def add_gems(condition, gems) condition ? gems.map {|g| "gem '#{g}'"}.join("\n") : "" end |
#file_generator(file, path = '../../template') ⇒ Object
31 32 33 |
# File 'lib/cear/file.rb', line 31 def file_generator(file, path = '../../template') eval('"' + ::File.open(::File.("#{path}/#{file}", __FILE__)).read + '"', binding, __FILE__, __LINE__) end |
#generate_file(filename, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cear/file.rb', line 35 def generate_file(filename, = {}) @filename = filename = {header: true}.merge(@options).merge() if ::File.exists?(@filename) == false or AskQuestion.new("Replace file #{@filename}?", "n/Y").ask != 'n' puts "Generate #{filename}".green ::File.open(@filename, 'w') do |file| if [:header] if template_exists?('.cear_header', ::File.('~/')) file.write(file_generator('.cear_header', ::File.('~/')) + "\n") else file.write(file_generator('header') + "\n") end end if template_exists?(@filename) file.write(file_generator(@filename)) else file.write("# require ::File.expand_path('../config/environment', __FILE__)\n") end end end end |
#run ⇒ Object
19 20 21 |
# File 'lib/cear/file.rb', line 19 def run generate_file(@app_name) end |
#template_exists?(file, path = '../../template') ⇒ Boolean
27 28 29 |
# File 'lib/cear/file.rb', line 27 def template_exists?(file, path = '../../template') ::File.exists?(::File.("#{path}/#{file}", __FILE__)) end |