Class: Base
- Inherits:
-
Object
show all
- Defined in:
- lib/mattermost/models/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(attrs) ⇒ Base
Returns a new instance of Base.
3
4
5
6
7
8
|
# File 'lib/mattermost/models/base.rb', line 3
def initialize(attrs)
attrs.each do |k,v|
singleton_class.class_eval { attr_accessor "#{k}" }
instance_variable_set "@#{k.to_sym}", v
end
end
|
Instance Method Details
#attributes ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/mattermost/models/base.rb', line 10
def attributes
return self.class.default_attributes unless defined?(@id)
hash = {}
self.instance_variables.each do |v|
hash[v.to_s.gsub('@', '').to_sym] = instance_variable_get(v)
end
hash
end
|
#first ⇒ Object
23
24
25
|
# File 'lib/mattermost/models/base.rb', line 23
def first
eval("Mattermost::#{self.class}").all.first
end
|
#last ⇒ Object
19
20
21
|
# File 'lib/mattermost/models/base.rb', line 19
def last
eval("Mattermost::#{self.class}").all.last
end
|
#to_json ⇒ Object
27
28
29
|
# File 'lib/mattermost/models/base.rb', line 27
def to_json
attributes.to_json
end
|