Skip to content

Commit

Permalink
Merge pull request #3877 from ChrisBr/refactoring/backend_info
Browse files Browse the repository at this point in the history
[api] Refactor BackendInfo class
  • Loading branch information
bgeuken committed Oct 5, 2017
2 parents ae463e2 + 971bd19 commit 75f6003
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/api/app/models/backend_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,16 @@ class BackendInfo < ApplicationRecord
#### Scopes (first the default_scope macro if is used)
#### Validations macros
#### Class methods using self. (public and then private)
def self.set_value(key, value)
backend_value = BackendInfo.find_or_initialize_by(key: key)
#### To define class methods as private use private_class_method
def self.lastnotification_nr=(value)
backend_value = BackendInfo.find_or_initialize_by(key: 'lastnotification_nr')
backend_value.value = value
backend_value.save!
end

def self.lastnotification_nr=(nr)
set_value('lastnotification_nr', nr.to_s)
end

def self.get_value(key)
BackendInfo.where(key: key).pluck(:value)
end

def self.get_integer(key)
nr = get_value(key)
nr.empty? ? 0 : nr[0].to_i
end

def self.lastnotification_nr
get_integer('lastnotification_nr')
BackendInfo.where(key: 'lastnotification_nr').pluck(:value).first.to_i
end

#### To define class methods as private use private_class_method
#### private
#### Instance methods (public and then protected/private)
#### Alias of methods
Expand Down

0 comments on commit 75f6003

Please sign in to comment.