Class: Widget::Data
- Inherits:
-
Object
- Object
- Widget::Data
- Includes:
- Singleton
- Defined in:
- lib/widget/widget_data.rb
Instance Method Summary collapse
-
#create(name) ⇒ Object
CRUD.
- #delete(name) ⇒ Object
-
#delete_all ⇒ Object
CRUD helpers.
-
#initialize(clean_slate = false) ⇒ Data
constructor
A new instance of Data.
- #length ⇒ Object (also: #count)
- #read(name) ⇒ Object
- #read_all ⇒ Object
- #reload ⇒ Object
- #update(name) ⇒ Object
Constructor Details
#initialize(clean_slate = false) ⇒ Data
Returns a new instance of Data.
9 10 11 12 13 |
# File 'lib/widget/widget_data.rb', line 9 def initialize(clean_slate=false) hm = HashModel.new (HashModel.new) unless File.exist?(HASHMODEL_FILE) || clean_slate @widgets = end |
Instance Method Details
#create(name) ⇒ Object
CRUD
22 23 24 25 26 27 28 |
# File 'lib/widget/widget_data.rb', line 22 def create(name) return false unless @widgets.where(name).empty? time_now = now @widgets.add(:name=>name, :created_at=>time_now, :modified_at=>time_now) true end |
#delete(name) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/widget/widget_data.rb', line 41 def delete(name) return false if @widgets.where(name).empty? @widgets.delete!(name) true end |
#delete_all ⇒ Object
CRUD helpers
50 51 52 53 |
# File 'lib/widget/widget_data.rb', line 50 def delete_all @widgets.clear end |
#length ⇒ Object Also known as: count
15 16 17 |
# File 'lib/widget/widget_data.rb', line 15 def length @widgets.length end |
#read(name) ⇒ Object
30 31 32 |
# File 'lib/widget/widget_data.rb', line 30 def read(name) @widgets.where(name) end |
#read_all ⇒ Object
55 56 57 |
# File 'lib/widget/widget_data.rb', line 55 def read_all @widgets.clone end |
#reload ⇒ Object
59 60 61 |
# File 'lib/widget/widget_data.rb', line 59 def reload end |
#update(name) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/widget/widget_data.rb', line 34 def update(name) # note the destructive update! method changed = !(@widgets.update!(name, :modified_at=>now).empty?) changed end |