lib/billomat/models/base.rb in billomat-0.4.1 vs lib/billomat/models/base.rb in billomat-1.0.0
- old
+ new
@@ -26,18 +26,21 @@
# @return [Array<Billomat::Models::Base>] the found records
def self.where(hash = {})
Billomat::Search.new(self, hash).run
end
- ##
# Initializes a new model.
#
# @param data [Hash] the attributes of the object
# @return [Billomat::Models::Base] the record as an object
+ #
+ # rubocop:disable Style/OpenStructUse because of the convenient
+ # dynamic data access
def initialize(data = {})
@data = OpenStruct.new(data)
end
+ # rubocop:enable Style/OpenStructUse
# Persists the current object in the API.
# When record is new it calls create, otherwise it saves the object.
#
# @return [TrueClass]
@@ -47,19 +50,23 @@
update
end
alias save! save
# @return [TrueClass]
+ #
+ # rubocop:disable Style/OpenStructUse because of the convenient
+ # dynamic data access
def create
resp = Billomat::Gateway.new(
:post, self.class.base_path, wrapped_data
).run
@data = OpenStruct.new(resp[self.class.resource_name])
true
end
alias create! create
+ # rubocop:enable Style/OpenStructUse
# @return [TrueClass]
def update
path = "#{self.class.base_path}/#{id}"
resp = Billomat::Gateway.new(:put, path, wrapped_data).run