Class: Bgem::TargetFile

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

Instance Method Summary collapse

Constructor Details

#initialize(path = 'output.rb', scope) ⇒ TargetFile

Returns a new instance of TargetFile.



96
97
98
99
# File 'lib/bgem.rb', line 96

def initialize path = 'output.rb', scope
  @path = Pathname path
  @scope = scope
end

Instance Method Details

#fileObject



113
114
115
# File 'lib/bgem.rb', line 113

def file
  @path
end

#write(string) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bgem.rb', line 101

def write string
  @path.dirname.mkpath

  if @scope
    @scope.each do |head_of_constant_definition|
      string = "#{head_of_constant_definition}\n#{string.indent INDENT}\nend"
    end
  end

  @path.write "#{string}\n"
end