Class: Ablerc::StubGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ablerc/stub_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ StubGenerator

Returns a new instance of StubGenerator.



7
8
9
10
11
# File 'lib/ablerc/stub_generator.rb', line 7

def initialize(options)
  self.header = options.delete :header
  self.footer = options.delete :footer
  self.options = options.delete :options
end

Instance Attribute Details

Returns the value of attribute footer.



4
5
6
# File 'lib/ablerc/stub_generator.rb', line 4

def footer
  @footer
end

#headerObject

Returns the value of attribute header.



4
5
6
# File 'lib/ablerc/stub_generator.rb', line 4

def header
  @header
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/ablerc/stub_generator.rb', line 4

def options
  @options
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/ablerc/stub_generator.rb', line 4

def path
  @path
end

Instance Method Details

#generate(context = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ablerc/stub_generator.rb', line 14

def generate(context = nil)
  begin
    context ||= Ablerc.contexts.names.last.to_sym
    path = File.expand_path(Ablerc.contexts.send(context.to_sym).path)
  rescue
    raise "Context does not exist"
  end

  puts "Generating Stub for #{context} in #{path + '/' + Ablerc.rc_file_name}".color :green

  begin
    File.open(path + '/' + Ablerc.rc_file_name, 'w') do |rc_file|
      rc_file << header.to_s unless header.nil?
      self.options.each do |option|
        rc_file << option.to_stub
      end
      rc_file << footer.to_s unless footer.nil?
    end
  rescue e
    puts "Error".color :red
    puts e
  end

  true
end

#write_description(description) ⇒ Object



40
41
# File 'lib/ablerc/stub_generator.rb', line 40

def write_description(description)
end