Class: Mastodon::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mastodon/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/mastodon/base.rb', line 8

def initialize(attributes = {})
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly) Also known as: to_h, to_hash

Returns the value of attribute attributes.



3
4
5
# File 'lib/mastodon/base.rb', line 3

def attributes
  @attributes
end

Class Method Details

.collection_attr_reader(attribute, klass) ⇒ Object



25
26
27
28
29
# File 'lib/mastodon/base.rb', line 25

def collection_attr_reader(attribute, klass)
  define_method(attribute) do
    Mastodon::Collection.new(@attributes[attribute.to_s], klass)
  end
end

.define_attribute_method(key) ⇒ Object



43
44
45
46
47
# File 'lib/mastodon/base.rb', line 43

def define_attribute_method(key)
  define_method(key) do
    @attributes[key.to_s]
  end
end

.define_predicate_method(key) ⇒ Object



37
38
39
40
41
# File 'lib/mastodon/base.rb', line 37

def define_predicate_method(key)
  define_method("#{key}?") do
    @attributes[key.to_s]
  end
end

.normal_attr_reader(*attributes) ⇒ Object



13
14
15
16
17
# File 'lib/mastodon/base.rb', line 13

def normal_attr_reader(*attributes)
  attributes.each do |attribute|
    define_attribute_method(attribute)
  end
end

.object_attr_reader(attribute, klass) ⇒ Object



19
20
21
22
23
# File 'lib/mastodon/base.rb', line 19

def object_attr_reader(attribute, klass)
  define_method(attribute) do
    klass.new(@attributes[attribute.to_s])
  end
end

.predicate_attr_reader(*attributes) ⇒ Object



31
32
33
34
35
# File 'lib/mastodon/base.rb', line 31

def predicate_attr_reader(*attributes)
  attributes.each do |attribute|
    define_predicate_method(attribute)
  end
end