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.



10
11
12
# File 'lib/mastodon/base.rb', line 10

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

Instance Attribute Details

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

Returns the value of attribute attributes.



5
6
7
# File 'lib/mastodon/base.rb', line 5

def attributes
  @attributes
end

Class Method Details

.collection_attr_reader(attribute, klass) ⇒ Object



27
28
29
30
31
# File 'lib/mastodon/base.rb', line 27

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



45
46
47
48
49
# File 'lib/mastodon/base.rb', line 45

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

.define_predicate_method(key) ⇒ Object



39
40
41
42
43
# File 'lib/mastodon/base.rb', line 39

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

.normal_attr_reader(*attributes) ⇒ Object



15
16
17
18
19
# File 'lib/mastodon/base.rb', line 15

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

.object_attr_reader(attribute, klass) ⇒ Object



21
22
23
24
25
# File 'lib/mastodon/base.rb', line 21

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

.predicate_attr_reader(*attributes) ⇒ Object



33
34
35
36
37
# File 'lib/mastodon/base.rb', line 33

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