Class: Vimdb::User
- Inherits:
-
Object
- Object
- Vimdb::User
- Defined in:
- lib/vimdb/user.rb
Instance Method Summary collapse
-
#initialize(item, db) ⇒ User
constructor
A new instance of User.
- #items ⇒ Object
- #reload ⇒ Object
- #search(query, options = {}) ⇒ Object
Constructor Details
#initialize(item, db) ⇒ User
Returns a new instance of User.
3 4 5 6 |
# File 'lib/vimdb/user.rb', line 3 def initialize(item, db) @item, @db = item, db @reload = !File.exists?(@db.file) end |
Instance Method Details
#items ⇒ Object
8 9 10 11 |
# File 'lib/vimdb/user.rb', line 8 def items !@reload && @db.get(@item.key) || @db.set(@item.key, @item.create).tap { @reload = false } end |
#reload ⇒ Object
22 23 24 |
# File 'lib/vimdb/user.rb', line 22 def reload @reload = true end |
#search(query, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/vimdb/user.rb', line 13 def search(query, = {}) results = @item.search(items.dup, query, ) results = items - results if [:not] sort = [:sort] || [:field] || @item.default_field results.sort_by! {|e| e[sort.to_sym] || '' } results.reverse! if [:reverse_sort] results end |