Class: TemplateBuilder::App::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/template_builder/app/file_manager.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FileManager

Returns a new instance of FileManager.



9
10
11
12
13
14
15
# File 'lib/template_builder/app/file_manager.rb', line 9

def initialize( opts = {} )
  self.file_name = opts[:file]
  self.verbose = opts[:verbose]
  self.file = File.new(self.file_name,  "w+")      
  @out = opts[:stdout] || $stdout
  @err = opts[:stderr] || $stderr
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



6
7
8
# File 'lib/template_builder/app/file_manager.rb', line 6

def file
  @file
end

#file_nameObject

Returns the value of attribute file_name.



6
7
8
# File 'lib/template_builder/app/file_manager.rb', line 6

def file_name
  @file_name
end

#verboseObject Also known as: verbose?

Returns the value of attribute verbose.



6
7
8
# File 'lib/template_builder/app/file_manager.rb', line 6

def verbose
  @verbose
end

Instance Method Details

#end_file(name, command) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/template_builder/app/file_manager.rb', line 38

def end_file(name, command)
  write "
# >-----------------------------[ Run Bundler ]-------------------------------<

say 'Running Bundler install. This will take a while.'
run 'bundle install'
say 'Running after Bundler callbacks.'
@after.each{|b| b.call}

# >---------------------------[ Install Command ]-----------------------------<
#  rails new APP_NAME -m "+name+" "+command.to_s+" -f
# >---------------------------------------------------------------------------<"
end

#start_file(config_file) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/template_builder/app/file_manager.rb', line 17

def start_file(config_file)
  write "#   This template was generated by template_builder, the amazing and awesome Rails
#     application builder.
#
initializer 'generators.rb', <<-RUBY
  Rails.application.config.generators do |g|
  end
RUBY"

  template = "template = {"
  config_file.each do |key, value| 
    template += "'"+key.to_s+"'=>'"+value.name+"',"
  end
  write template[0..template.length-2]+"}"
  
  write"recipes = template.values.flatten

@after = []
def after_bundler(&block); @after << block; end"
end

#write(content) ⇒ Object



52
53
54
# File 'lib/template_builder/app/file_manager.rb', line 52

def write(content)
  self.file.write content+"\n"
end

#write_action(action) ⇒ Object



60
61
62
63
64
# File 'lib/template_builder/app/file_manager.rb', line 60

def write_action(action)
  write "after_bundler do\n"
  action.each{ |act| write "\t"+act.to_s }
  write "end"
end

#write_framework_introduction(name) ⇒ Object



66
67
68
69
70
# File 'lib/template_builder/app/file_manager.rb', line 66

def write_framework_introduction(name)
  write "
#  ---------------------------------------------------------------------------
# >----------------------------[ "+name+"]------------------------------<"
end

#write_gem(gem) ⇒ Object



56
57
58
# File 'lib/template_builder/app/file_manager.rb', line 56

def write_gem(gem)
  write "gem "+gem
end