Class: Tairb::Configuration

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

Constant Summary collapse

DEFAULTS =
{
  bytes: 10000
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, config = {}) ⇒ Configuration

Returns a new instance of Configuration.



10
11
12
13
14
15
16
# File 'lib/tairb/configuration.rb', line 10

def initialize context, config={}
  @context = context
  config = DEFAULTS.merge config
  %i[ type bytes filter script ].each do |key|
    self.send "#{key}=", config[key] if config.key? key
  end
end

Instance Attribute Details

#bytesObject

Returns the value of attribute bytes.



7
8
9
# File 'lib/tairb/configuration.rb', line 7

def bytes
  @bytes
end

#filterObject

Returns the value of attribute filter.



8
9
10
# File 'lib/tairb/configuration.rb', line 8

def filter
  @filter
end

#scriptObject

Returns the value of attribute script.



7
8
9
# File 'lib/tairb/configuration.rb', line 7

def script
  @script
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/tairb/configuration.rb', line 7

def type
  @type
end

Instance Method Details

#default_scriptObject



30
31
32
33
# File 'lib/tairb/configuration.rb', line 30

def default_script
  serialize = @context.method default_serialize
  proc { |dat| puts serialize.call(dat) }
end

#default_serializeObject



34
35
36
37
38
39
# File 'lib/tairb/configuration.rb', line 34

def default_serialize
  case self.type
  when :tsv then :to_tsv
  else :to_s
  end
end

#tailf_methodObject



23
24
25
26
27
28
# File 'lib/tairb/configuration.rb', line 23

def tailf_method
  case self.type
  when :tsv then :tailf_tsv
  else :tailf
  end
end