lib/qismo/model.rb in qismo-0.9.0 vs lib/qismo/model.rb in qismo-0.10.0
- old
+ new
@@ -1,18 +1,18 @@
# frozen_string_literal: true
module Qismo
# Class to handle http response body
#
- class DataObject
+ class SingleObject
# Initiate data object
#
# @param opt [Hash]
def initialize(opt = {})
opt.each do |key, value|
value = if value.is_a?(Array)
- handle_array(value)
+ CollectionObject.new(handle_array(value))
elsif value.is_a?(Hash)
self.class.new(value)
elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
self.class.define_method("#{key.to_s.delete_prefix("is_")}?".to_sym) { value }
value
@@ -52,19 +52,19 @@
end
end
# Class to handle response body that contain pagination
#
- class Collection < Array
+ class CollectionObject < Array
# Initiate collection
#
- # @param data [Qismo::DataObject]
+ # @param data [Qismo::SingleObject]
# @param prev_page [String, Integer]
# @param next_page [String, Integer]
# @param prev_func [Proc, NilClass]
# @param next_func [Proc, NilClass]
- def initialize(data, prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
+ def initialize(data = [], prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
super(data)
@prev_page = prev_page
@next_page = next_page
@prev_func = prev_func
@@ -85,17 +85,17 @@
alias_method :prev_page?, :has_prev_page?
# Call api request for next page
#
- # @return [Qismo::DataObject, Qismo::Collection]
+ # @return [Qismo::SingleObject, Qismo::CollectionObject]
def next_page
@next_func.call if has_next_page?
end
# Call api request for previous page
#
- # @return [Qismo::DataObject, Qismo::Collection]
+ # @return [Qismo::SingleObject, Qismo::CollectionObject]
def prev_page
@prev_func.call if has_prev_page?
end
end
end