lib/yao/resources/base.rb in yao-0.15.0 vs lib/yao/resources/base.rb in yao-0.16.0

- old
+ new

@@ -6,13 +6,10 @@ # @param name [Array] def self.friendly_attributes(*names) names.map(&:to_s).each do |name| define_method(name) do - if !@data.key?(name) && id - @data = self.class.get(id).to_hash - end self[name] end end end @@ -56,10 +53,13 @@ end # @param name [String] # @return [String] def [](name) + unless @data["id"].nil? || @data.key?(name) || name.include?("__") + @data = self.class.get(@data["id"]).to_hash + end @data[name] end # @param name [String] # @param value [String] @@ -78,20 +78,32 @@ self["id"] end # @return [Date] def created - if date = self["created"] || self["created_at"] + if date = self["created_at"] || self["created"] Time.parse(date) end end # @return [Date] def updated - if date = self["updated"] || self["updated_at"] + if date = self["updated_at"] || self["updated"] Time.parse(date) end end + + # @param resource_params [Hash] + # @return [Yao::Resources::*] + def update(resource_params) + self.class.update(id, resource_params) + end + + # @return [String] + def destroy + self.class.destroy(id) + end + alias delete destroy extend RestfullyAccessible end end