Class: Apache::Log::Directive

Inherits:
Object
  • Object
show all
Defined in:
lib/aplo/strptime.rb,
lib/aplo/directive.rb,
lib/aplo/directives.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Directive

Returns a new instance of Directive.



18
19
20
21
22
23
24
# File 'lib/aplo/directive.rb', line 18

def initialize(str)
  @name, @pattern, @conversion = @@directives[str[-1, 1]]

  if /\{(.+)\}/ =~ str
    @key = $1
  end
end

Instance Attribute Details

#keyObject (readonly) Also known as: format

Returns the value of attribute key.



14
15
16
# File 'lib/aplo/directive.rb', line 14

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/aplo/directive.rb', line 14

def name
  @name
end

Class Method Details

.convert(directive, conversion = nil, &converter) ⇒ Object



9
10
11
# File 'lib/aplo/directive.rb', line 9

def convert(directive, conversion = nil, &converter)
  converters[directive] = conversion || converter
end

.convertersObject



49
50
51
# File 'lib/aplo/directive.rb', line 49

def converters
  @@converters ||= {}
end

.dir(char, name, pattern = nil) ⇒ Object



6
7
8
# File 'lib/aplo/directive.rb', line 6

def dir(char, name, pattern = nil)
  directives[char] = [name, pattern]
end

.directivesObject



46
47
48
# File 'lib/aplo/directive.rb', line 46

def directives
  @@directives ||= {}
end

Instance Method Details

#formatted?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/aplo/directive.rb', line 34

def formatted?
  @name == :time || @name == :process_id
end

#keyed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/aplo/directive.rb', line 30

def keyed?
  !@key.nil?
end

#patternObject



26
27
28
# File 'lib/aplo/directive.rb', line 26

def pattern
  @pattern ||= '(.+?)'
end

#process(str) ⇒ Object



38
39
40
# File 'lib/aplo/directive.rb', line 38

def process(str)
  str == '-' ? nil : convert(str)
end