Module: LogStash::Modules::ResourceBase

Included in:
ElasticsearchResource, KibanaResource
Defined in:
lib/logstash/modules/resource_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



6
7
8
# File 'lib/logstash/modules/resource_base.rb', line 6

def base
  @base
end

#content_idObject (readonly)

Returns the value of attribute content_id.



6
7
8
# File 'lib/logstash/modules/resource_base.rb', line 6

def content_id
  @content_id
end

#content_pathObject (readonly)

Returns the value of attribute content_path.



6
7
8
# File 'lib/logstash/modules/resource_base.rb', line 6

def content_path
  @content_path
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



6
7
8
# File 'lib/logstash/modules/resource_base.rb', line 6

def content_type
  @content_type
end

Instance Method Details

#<=>(other) ⇒ Object



30
31
32
# File 'lib/logstash/modules/resource_base.rb', line 30

def <=>(other)
  to_s <=> other.to_s
end

#==(other) ⇒ Object



34
35
36
# File 'lib/logstash/modules/resource_base.rb', line 34

def ==(other)
  to_s == other.to_s
end

#contentObject



18
19
20
# File 'lib/logstash/modules/resource_base.rb', line 18

def content
  @content ||= FileReader.read(@content_path)
end

#content_as_objectObject



26
27
28
# File 'lib/logstash/modules/resource_base.rb', line 26

def content_as_object
  @content_as_object ||= FileReader.read_json(@content_path) rescue nil
end

#initialize(base, content_type, content_path, content = nil, content_id = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/logstash/modules/resource_base.rb', line 8

def initialize(base, content_type, content_path, content = nil, content_id = nil)
  @base, @content_type, @content_path = base, content_type, content_path
  @content_id =  content_id || ::File.basename(@content_path, ".*")
  # content at this time will be a JSON string
  @content = content
  if !@content.nil?
    @content_as_object = LogStash::Json.load(@content) rescue {}
  end
end

#to_sObject



22
23
24
# File 'lib/logstash/modules/resource_base.rb', line 22

def to_s
  "#{base}, #{content_type}, #{content_path}, #{content_id}"
end