Class: Ably::Models::Stats::StatsStruct Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ably/models/stats_types.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

StatsStruct is a basic Struct like class that allows methods to be defined on the class that will be retuned co-erced objects from the underlying hash used to initialize the object.

This class provides a concise way to create classes that have fixed attributes and types

Examples:

class MessageCount < StatsStruct
  coerce_attributes :count, :data, into: Integer
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ StatsStruct

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StatsStruct.



46
47
48
# File 'lib/ably/models/stats_types.rb', line 46

def initialize(hash)
  @hash = hash || {}
end

Instance Attribute Details

#hashObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/ably/models/stats_types.rb', line 44

def hash
  @hash
end

Class Method Details

.coerce_attributes(*attributes) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
# File 'lib/ably/models/stats_types.rb', line 18

def coerce_attributes(*attributes)
  options = attributes.pop
  raise ArgumentError, 'Expected attribute into: within options hash' unless options.kind_of?(Hash) && options[:into]

  @type_klass = options[:into]
  setup_attribute_methods attributes
end

.type_klassObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/ably/models/stats_types.rb', line 26

def type_klass
  @type_klass
end