Class: Bgem::TargetFile

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

Instance Method Summary collapse

Constructor Details

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



111
112
113
114
115
116
117
118
119
# File 'lib/bgem.rb', line 111

def initialize path = 'output.rb', scope = nil
  @path = Pathname path
  @scope = case scope
           when Array
             scope
           when String
             eval scope
           end
end

Instance Method Details

#fileObject



133
134
135
# File 'lib/bgem.rb', line 133

def file
  @path
end

#write(string) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/bgem.rb', line 121

def write string
  @path.dirname.mkpath

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

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