Module: Rentlinx::Amenityable
Overview
Instance Method Summary collapse
-
#add_amenity(options) ⇒ Object
Builds a single amenity and attaches it to the object.
-
#amenities ⇒ Object
Loads and caches the list of amenities from Rentlinx.
-
#amenities=(amenity_list) ⇒ Object
Allows assignment of amenities to the object.
-
#post_amenities ⇒ Object
Posts the object’s amenities.
-
#post_with_amenities ⇒ Object
Posts the object with its associated amenities.
Instance Method Details
#add_amenity(options) ⇒ Object
Builds a single amenity and attaches it to the object. This method conveniently assigns the propertyID and unitID (if present) of the parent object, so these need not be passed.
60 61 62 63 64 65 |
# File 'lib/rentlinx/modules/amenityable.rb', line 60 def add_amenity() [:propertyID] = propertyID [:unitID] = unitID if defined? unitID @amenities ||= [] @amenities << amenity_class.new() end |
#amenities ⇒ Object
Loads and caches the list of amenities from Rentlinx.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rentlinx/modules/amenityable.rb', line 30 def amenities return @amenities if @amenities @amenities = if defined? unitID Rentlinx.client.get_amenities_for_unit(self) else Rentlinx.client.get_amenities_for_property_id(propertyID) end end |
#amenities=(amenity_list) ⇒ Object
Allows assignment of amenities to the object.
45 46 47 48 49 50 51 |
# File 'lib/rentlinx/modules/amenityable.rb', line 45 def amenities=(amenity_list) @amenities = amenity_list.map do |amenity| amenity.propertyID = propertyID amenity.unitID = unitID if defined? unitID amenity end end |
#post_amenities ⇒ Object
Posts the object’s amenities
17 18 19 20 21 22 23 24 25 |
# File 'lib/rentlinx/modules/amenityable.rb', line 17 def post_amenities return if @amenities.nil? if @amenities.empty? Rentlinx.client.unpost_amenities_for(self) else Rentlinx.client.post_amenities(@amenities) end end |
#post_with_amenities ⇒ Object
Posts the object with its associated amenities
TODO: Discuss whether or not these kinds of methods are needed, or whether we should have post do everything every time.
11 12 13 14 |
# File 'lib/rentlinx/modules/amenityable.rb', line 11 def post_with_amenities post post_amenities end |