Class: Helium::Resource
- Inherits:
-
Object
- Object
- Helium::Resource
- Defined in:
- lib/helium/resource.rb
Overview
Abstract base class for Helium Resources returned by the API
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Override equality to use id for comparisons.
-
#as_json ⇒ Hash
Inheriting resources should implement this with super.
-
#created_at ⇒ DateTime?
When the resource was created.
-
#eql?(other) ⇒ Boolean
Override equality to use id for comparisons.
-
#hash ⇒ Integer
Override equality to use id for comparisons.
-
#initialize(client:, params:) ⇒ Resource
constructor
A new instance of Resource.
-
#to_json(*options) ⇒ String
A JSON-encoded String representing the resource.
-
#updated_at ⇒ DateTime?
When the resource was last updated.
Constructor Details
#initialize(client:, params:) ⇒ Resource
Returns a new instance of Resource
6 7 8 9 10 11 |
# File 'lib/helium/resource.rb', line 6 def initialize(client:, params:) @client = client @id = params["id"] @created_at = params.dig('meta', 'created') @updated_at = params.dig('meta', 'updated') end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id
4 5 6 |
# File 'lib/helium/resource.rb', line 4 def id @id end |
Instance Method Details
#==(other) ⇒ Boolean
Override equality to use id for comparisons
15 16 17 |
# File 'lib/helium/resource.rb', line 15 def ==(other) self.id == other.id end |
#as_json ⇒ Hash
Inheriting resources should implement this with super
45 46 47 48 49 50 51 |
# File 'lib/helium/resource.rb', line 45 def as_json { id: id, created_at: created_at, updated_at: updated_at } end |
#created_at ⇒ DateTime?
Returns when the resource was created
32 33 34 35 |
# File 'lib/helium/resource.rb', line 32 def created_at return nil if @created_at.nil? @_created_at ||= DateTime.parse(@created_at) end |
#eql?(other) ⇒ Boolean
Override equality to use id for comparisons
21 22 23 |
# File 'lib/helium/resource.rb', line 21 def eql?(other) self == other end |
#hash ⇒ Integer
Override equality to use id for comparisons
27 28 29 |
# File 'lib/helium/resource.rb', line 27 def hash id.hash end |
#to_json(*options) ⇒ String
Returns a JSON-encoded String representing the resource
54 55 56 |
# File 'lib/helium/resource.rb', line 54 def to_json(*) as_json.to_json(*) end |
#updated_at ⇒ DateTime?
Returns when the resource was last updated
38 39 40 41 |
# File 'lib/helium/resource.rb', line 38 def updated_at return nil if @updated_at.nil? @_updated_at ||= DateTime.parse(@updated_at) end |