Class: Yell::Adapters::Collection

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Collection

Returns a new instance of Collection.



12
13
14
15
# File 'lib/yell/adapters.rb', line 12

def initialize( options = {} )
  @options = options
  @collection = []
end

Instance Method Details

#add(type = :file, *args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yell/adapters.rb', line 17

def add( type = :file, *args, &block )
  options = [@options, *args].inject(Hash.new) do |h, c|
    h.merge( [String, Pathname].include?(c.class) ? {:filename => c} : c  )
  end

  # remove possible :null adapters
  @collection.shift if @collection.first.instance_of?(Yell::Adapters::Base)

  new_adapter = Yell::Adapters.new(type, options, &block)
  @collection.push(new_adapter)

  new_adapter
end

#closeObject



42
43
44
# File 'lib/yell/adapters.rb', line 42

def close
  @collection.each { |c| c.close }
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/yell/adapters.rb', line 31

def empty?
  @collection.empty?
end

#write(event) ⇒ Object



36
37
38
39
# File 'lib/yell/adapters.rb', line 36

def write( event )
  @collection.each { |c| c.write(event) }
  true
end