Class: Wimdu::Property
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/wimdu/property.rb
Defined Under Namespace
Classes: InvalidPropertyError, NothingToContinue
Constant Summary
collapse
- ATTRIBUTES =
[:title, :property_type, :nightly_rate, :max_guests, :email, :phone_number]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Property.
24
25
26
|
# File 'lib/wimdu/property.rb', line 24
def initialize
@_id = SecureRandom.hex(5)
end
|
Instance Attribute Details
#_id ⇒ Object
Returns the value of attribute _id.
9
10
11
|
# File 'lib/wimdu/property.rb', line 9
def _id
@_id
end
|
Class Method Details
.connection ⇒ Object
48
49
50
|
# File 'lib/wimdu/property.rb', line 48
def connection
@connection ||= PStore.new('wimdu.db')
end
|
.delete_all ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/wimdu/property.rb', line 58
def delete_all
transaction do
connection.roots.each do |key|
connection.delete(key)
end
end
end
|
.find(id) ⇒ Object
70
71
72
|
# File 'lib/wimdu/property.rb', line 70
def find(id)
transaction{connection[id]}
end
|
.list ⇒ Object
66
67
68
|
# File 'lib/wimdu/property.rb', line 66
def list
transaction{connection.roots.map{|id| connection[id]}.map{|property| property._id}}
end
|
.transaction ⇒ Object
52
53
54
55
56
|
# File 'lib/wimdu/property.rb', line 52
def transaction
connection.transaction do
yield
end
end
|
.unsaved_attributes(property) ⇒ Object
Instance Method Details
#delete(key) ⇒ Object
42
43
44
|
# File 'lib/wimdu/property.rb', line 42
def delete(key)
transaction{connection.delete(key)}
end
|
#save ⇒ Object
37
38
39
40
|
# File 'lib/wimdu/property.rb', line 37
def save
raise InvalidPropertyError, errors.full_messages.join unless valid?
transaction{connection[@_id] = self}
end
|
#update_attribute(attribute, value) ⇒ Object
32
33
34
35
|
# File 'lib/wimdu/property.rb', line 32
def update_attribute(attribute, value)
self.send("#{attribute}=", value)
self.save
end
|