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.



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

def base
  @base
end

#content_idObject (readonly)

Returns the value of attribute content_id.



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

def content_id
  @content_id
end

#content_pathObject (readonly)

Returns the value of attribute content_path.



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

def content_path
  @content_path
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



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

def content_type
  @content_type
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#contentObject



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

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

#content_as_objectObject



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

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



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

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



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

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