Class: ExpressTranslate::ExpressTranslateModel
- Inherits:
-
Object
- Object
- ExpressTranslate::ExpressTranslateModel
- Defined in:
- lib/express_translate/express_translate_model.rb
Overview
Construction
id: xyz
......
......
Direct Known Subclasses
Class Attribute Summary collapse
-
.attr ⇒ Object
Returns the value of attribute attr.
-
.has_many ⇒ Object
Returns the value of attribute has_many.
-
.name ⇒ Object
Returns the value of attribute name.
-
.primary ⇒ Object
Returns the value of attribute primary.
-
.unique ⇒ Object
Returns the value of attribute unique.
Class Method Summary collapse
-
.add(params) ⇒ Object
Add item with params Check primary key for present Check unique data Return messages.
-
.all ⇒ Object
get all item in table.
-
.delete(id) ⇒ Object
Delete item by id Remove item with primary key.
-
.destroy ⇒ Object
Clear all data of table.
-
.find(code) ⇒ Object
Find item by code Select item with primary key return limit items selected.
-
.save(obj) ⇒ Object
Save obj to redis database Synchronize data to redis database.
-
.update(params) ⇒ Object
Update item by params Remove old item Add new item with exsits data Return json data for status.
Class Attribute Details
.attr ⇒ Object
Returns the value of attribute attr.
9 10 11 |
# File 'lib/express_translate/express_translate_model.rb', line 9 def attr @attr end |
.has_many ⇒ Object
Returns the value of attribute has_many.
9 10 11 |
# File 'lib/express_translate/express_translate_model.rb', line 9 def has_many @has_many end |
.name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/express_translate/express_translate_model.rb', line 9 def name @name end |
.primary ⇒ Object
Returns the value of attribute primary.
9 10 11 |
# File 'lib/express_translate/express_translate_model.rb', line 9 def primary @primary end |
.unique ⇒ Object
Returns the value of attribute unique.
9 10 11 |
# File 'lib/express_translate/express_translate_model.rb', line 9 def unique @unique end |
Class Method Details
.add(params) ⇒ Object
Add item with params Check primary key for present Check unique data Return messages
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/express_translate/express_translate_model.rb', line 48 def self.add(params) if JSON.parse(params.to_json)[@primary] == "" return self.primary_nil end if self.check_unique_allow_add(params) data = self.all.push(params) self.save(data) return self.successful(data) else return self.primary_key end end |
.all ⇒ Object
get all item in table
25 26 27 28 29 30 31 |
# File 'lib/express_translate/express_translate_model.rb', line 25 def self.all data = Database.get(@name) data = data.nil? ? [] : (data.is_a?(Array) ? data : [].push(data)) self.add_has_many(data) data.sort_by!{|item| item.first} data end |
.delete(id) ⇒ Object
Delete item by id Remove item with primary key
63 64 65 66 67 68 |
# File 'lib/express_translate/express_translate_model.rb', line 63 def self.delete(id) all = self.all count_before = all.count all.reject!{|package| package[@primary] == id} return self.change_data(count_before, all.count, all) end |
.destroy ⇒ Object
Clear all data of table
40 41 42 |
# File 'lib/express_translate/express_translate_model.rb', line 40 def self.destroy Database.del(@name) end |
.find(code) ⇒ Object
Find item by code Select item with primary key return limit items selected
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/express_translate/express_translate_model.rb', line 86 def self.find(code) data = self.all search = data.select{|package| package[@primary] == code} if (search.count > 0) self.add_has_many_item(search[0]) else search = [nil] end return search[0] end |
.save(obj) ⇒ Object
Save obj to redis database Synchronize data to redis database
35 36 37 |
# File 'lib/express_translate/express_translate_model.rb', line 35 def self.save(obj) Database.set(@name, self.protect_attr_items(obj)) end |
.update(params) ⇒ Object
Update item by params Remove old item Add new item with exsits data Return json data for status
74 75 76 77 78 79 80 81 |
# File 'lib/express_translate/express_translate_model.rb', line 74 def self.update(params) all = self.all count_before = all.count all.reject!{|package| package[@primary] == params[@primary]} count_after = all.count all.push(params) if count_before > count_after return self.change_data(count_before, count_after, all) end |