Class: Harvesting::Models::Base
- Inherits:
-
Object
- Object
- Harvesting::Models::Base
show all
- Defined in:
- lib/harvesting/models/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs, opts = {}) ⇒ Base
Returns a new instance of Base.
7
8
9
10
|
# File 'lib/harvesting/models/base.rb', line 7
def initialize(attrs, opts = {})
@attributes = attrs.dup
@client = opts[:client] || Harvesting::Client.new(opts)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4
5
6
|
# File 'lib/harvesting/models/base.rb', line 4
def attributes
@attributes
end
|
#client ⇒ Object
Returns the value of attribute client.
5
6
7
|
# File 'lib/harvesting/models/base.rb', line 5
def client
@client
end
|
Class Method Details
.attributed(*attribute_names) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/harvesting/models/base.rb', line 12
def self.attributed(*attribute_names)
attribute_names.each do |attribute_name|
Harvesting::Models::Base.send :define_method, attribute_name.to_s do
@attributes[__method__.to_s]
end
end
end
|
Instance Method Details
#create ⇒ Object
24
25
26
|
# File 'lib/harvesting/models/base.rb', line 24
def create
@client.create(self)
end
|
#save ⇒ Object
20
21
22
|
# File 'lib/harvesting/models/base.rb', line 20
def save
id.nil? ? create : update
end
|
#to_hash ⇒ Object
32
33
34
|
# File 'lib/harvesting/models/base.rb', line 32
def to_hash
@attributes
end
|
#update ⇒ Object
28
29
30
|
# File 'lib/harvesting/models/base.rb', line 28
def update
@client.update(self)
end
|