Class: Adalog::Entry
- Inherits:
-
Object
- Object
- Adalog::Entry
- Defined in:
- lib/adalog/entry.rb
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #details_blank? ⇒ Boolean
-
#format ⇒ Object
TODO: Make this something we store and/or can override.
-
#initialize(title: nil, timestamp: nil, message: nil, details: nil, format: nil) ⇒ Entry
constructor
A new instance of Entry.
- #valid? ⇒ Boolean
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 = || Time.now @message = || '' @details = details || '' @format = format || 'json' validate! end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
33 34 35 |
# File 'lib/adalog/entry.rb', line 33 def details @details end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
33 34 35 |
# File 'lib/adalog/entry.rb', line 33 def errors @errors end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
33 34 35 |
# File 'lib/adalog/entry.rb', line 33 def @message end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
33 34 35 |
# File 'lib/adalog/entry.rb', line 33 def @timestamp end |
#title ⇒ Object (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, **) arguments = if nil == obj elsif obj.is_a?(Hash) || obj.respond_to?(:[]) obj elsif obj.respond_to?(:to_h) obj.to_h.merge() else { title: obj.respond_to?(:title) && obj.title, timestamp: obj.respond_to?(:timestamp) && obj., message: obj.respond_to?(:message) && obj., details: obj.respond_to?(:details) && obj.details, format: obj.respond_to?(:format) && obj.format, }.merge() 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
56 57 58 |
# File 'lib/adalog/entry.rb', line 56 def details_blank? blank?(details) end |
#format ⇒ Object
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
45 46 47 |
# File 'lib/adalog/entry.rb', line 45 def valid? @errors.none? end |