Class: Userlist::Push::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/userlist/push/resource.rb

Direct Known Subclasses

Company, Event, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



16
17
18
# File 'lib/userlist/push/resource.rb', line 16

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



28
29
30
31
32
33
34
35
36
37
# File 'lib/userlist/push/resource.rb', line 28

def method_missing(method, *args, &block)
  if method.to_s =~ /=$/
    attribute = method.to_s.sub(/=$/, '')
    attributes[attribute.to_sym] = args.first
  elsif attributes.key?(method.to_sym)
    attributes[method.to_sym]
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



14
15
16
# File 'lib/userlist/push/resource.rb', line 14

def attributes
  @attributes
end

Class Method Details

.endpointObject



9
10
11
# File 'lib/userlist/push/resource.rb', line 9

def endpoint
  "/#{resource_name.downcase}s"
end

.resource_nameObject



5
6
7
# File 'lib/userlist/push/resource.rb', line 5

def resource_name
  name.split('::')[-1]
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/userlist/push/resource.rb', line 20

def respond_to_missing?(method, include_private = false)
  attribute = method.to_s.sub(/=$/, '')

  attributes.key?(attribute.to_sym) || super
end