Class: Adalog::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/adalog/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, timestamp: nil, message: nil, details: nil, format: nil) ⇒ Entry

Returns a new instance of Entry.



35
36
37
38
39
40
41
42
# File 'lib/adalog/entry.rb', line 35

def initialize(title: nil, timestamp: nil, message: nil, details: nil, format: nil)
  @title      = title     || ''
  @timestamp  = timestamp || Time.now
  @message    = message   || ''
  @details    = details   || ''
  @format     = format    || 'json'
  validate!
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



33
34
35
# File 'lib/adalog/entry.rb', line 33

def details
  @details
end

#errorsObject (readonly)

Returns the value of attribute errors.



33
34
35
# File 'lib/adalog/entry.rb', line 33

def errors
  @errors
end

#messageObject (readonly)

Returns the value of attribute message.



33
34
35
# File 'lib/adalog/entry.rb', line 33

def message
  @message
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



33
34
35
# File 'lib/adalog/entry.rb', line 33

def timestamp
  @timestamp
end

#titleObject (readonly)

Returns the value of attribute title.



33
34
35
# File 'lib/adalog/entry.rb', line 33

def title
  @title
end

Class Method Details

.build(obj = nil, **options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/adalog/entry.rb', line 7

def self.build(obj = nil, **options)
  arguments =
    if nil == obj
      options
    elsif obj.is_a?(Hash) || obj.respond_to?(:[])
      obj
    elsif obj.respond_to?(:to_h)
      obj.to_h.merge(options)
    else
      { title:      obj.respond_to?(:title)     && obj.title,
        timestamp:  obj.respond_to?(:timestamp) && obj.timestamp,
        message:    obj.respond_to?(:message)   && obj.message,
        details:    obj.respond_to?(:details)   && obj.details,
        format:     obj.respond_to?(:format)    && obj.format,
      }.merge(options)
    end

  self.new(
    title:      arguments[:title]     || arguments['title'],
    timestamp:  arguments[:timestamp] || arguments['timestamp'],
    message:    arguments[:message]   || arguments['message'],
    details:    arguments[:details]   || arguments['details'],
    format:     arguments[:format]    || arguments['format'],
  )
end

Instance Method Details

#details_blank?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/adalog/entry.rb', line 56

def details_blank?
  blank?(details)
end

#formatObject

TODO: Make this something we store and/or can override.



51
52
53
# File 'lib/adalog/entry.rb', line 51

def format
  :json
end

#valid?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/adalog/entry.rb', line 45

def valid?
  @errors.none?
end