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.



14
15
16
17
# File 'lib/yell/adapters.rb', line 14

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

Instance Method Details

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



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

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



44
45
46
# File 'lib/yell/adapters.rb', line 44

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

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/yell/adapters.rb', line 33

def empty?
  @collection.empty?
end

#write(event) ⇒ Object



38
39
40
41
# File 'lib/yell/adapters.rb', line 38

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