class StripeMock::Data::List
Attributes
data[R]
ending_before[R]
limit[R]
offset[R]
starting_after[R]
Public Class Methods
new(data, options = {})
click to toggle source
# File lib/stripe_mock/data/list.rb, line 6 def initialize(data, options = {}) @data = Array(data.clone) @limit = [[options[:limit] || 10, 100].min, 1].max # restrict @limit to 1..100 @starting_after = options[:starting_after] @ending_before = options[:ending_before] if @data.first.is_a?(Hash) && @data.first[:created] @data.sort_by! { |x| x[:created] } @data.reverse! elsif @data.first.respond_to?(:created) @data.sort_by { |x| x.created } @data.reverse! end end
Public Instance Methods
has_more?()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 29 def has_more? (offset + limit) < data.size end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/stripe_mock/data/list.rb, line 33 def method_missing(method_name, *args, &block) hash = to_hash if hash.keys.include?(method_name) hash[method_name] else super end end
respond_to?(method_name, priv = false)
click to toggle source
Calls superclass method
# File lib/stripe_mock/data/list.rb, line 43 def respond_to?(method_name, priv = false) to_hash.keys.include?(method_name) || super end
to_hash()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 24 def to_hash { object: "list", data: data_page, url: url, has_more: has_more? } end
Also aliased as: to_h
url()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 20 def url "/v1/#{object_types}" end
Private Instance Methods
data_page()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 62 def data_page data[offset, limit] end
object_types()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 66 def object_types if first_object = data[0] "#{first_object.class.to_s.split('::')[-1].downcase}s" end end