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.



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

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

Instance Method Details

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



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

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



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @collection.empty?
end

#write(event) ⇒ Object



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

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