Class: Imgur::Model

Inherits:
Cistern::Model
  • Object
show all
Defined in:
lib/imgur/model.rb

Class Method Summary collapse

Class Method Details

.assoc_accessor(name) ⇒ Object



14
15
16
17
# File 'lib/imgur/model.rb', line 14

def self.assoc_accessor(name)
  assoc_reader(name)
  assoc_writer(name)
end

.assoc_reader(name) ⇒ Object



2
3
4
5
6
# File 'lib/imgur/model.rb', line 2

def self.assoc_reader(name)
  define_method(name) do
    send("#{name}_id".to_sym) && self.connection.send("#{name}s").get(self.send("#{name}_id"))
  end
end

.assoc_writer(name) ⇒ Object



8
9
10
11
12
# File 'lib/imgur/model.rb', line 8

def self.assoc_writer(name)
  define_method("#{name}=") do |value|
    self.send("#{name}_id=", value.id) if value
  end
end