Class: Swig::Stream

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStream

Returns a new instance of Stream.



8
9
10
# File 'lib/swig/stream.rb', line 8

def initialize
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/swig/stream.rb', line 6

def files
  @files
end

Instance Method Details

#clean(pattern = //) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/swig/stream.rb', line 32

def clean(pattern = //)
  @files = @files.reject do |file|
    pattern =~ file.basename
  end

  self
end

#read(path_or_paths) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/swig/stream.rb', line 12

def read(path_or_paths)
  Dir.glob(path_or_paths).each do |path|
    basename = File.basename(path)
    content = File.read(path)
    @files << Swig::FileInStream.new(basename, content)
  end

  self
end

#then(klass, options = {}) ⇒ Object



40
41
42
43
44
# File 'lib/swig/stream.rb', line 40

def then(klass, options = {})
  @files = klass.new(options).eval(@files)

  self
end

#write(path) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/swig/stream.rb', line 22

def write(path)
  FileUtils.mkdir_p(path)

  @files.each do |file|
    File.write(File.join(path, file.basename), file.read)
  end

  self
end