Class: HelloServerClient::Notification
- Inherits:
-
Ohm::Model
- Object
- Ohm::Model
- HelloServerClient::Notification
- Includes:
- Ohm::DataTypes, Ohm::Timestamps
- Defined in:
- lib/hello_server_client/notification.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#updated_time ⇒ Object
INFO: add oj gem attribute :value_json def value nil if self.value_json.nil? Oj.load(self.value_json.to_s) end.
Class Method Details
.find_by_name(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hello_server_client/notification.rb', line 31 def self.find_by_name(name) @@index = Hash.new unless defined? @@index id = @@index[name] if id # something is indexed obj = self[id] if obj and obj.name == name # good index return obj else @@index.delete(name) return nil end else # get object obj = self.all.select { |o| o.name == name }.first if obj @@index[name] = obj.id return obj else return nil end end end |
.find_or_initialize_by_name(name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hello_server_client/notification.rb', line 20 def self.find_or_initialize_by_name(name) # find doesn't work #s = self.find(name: name) s = find_by_name(name) if s.nil? s = self.new s.name = name end return s end |
Instance Method Details
#updated_time ⇒ Object
INFO: add oj gem attribute :value_json def value
nil if self.value_json.nil?
Oj.load(self.value_json.to_s)
end
def value=(obj)
if obj.nil?
self.value_json = nil
return
end
self.value_json = Oj.dump(obj)
end
71 72 73 |
# File 'lib/hello_server_client/notification.rb', line 71 def updated_time Time.at(self.updated_at.to_i) end |