class StripeMock::Data::List
Attributes
active[R]
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] @active = options[:active] 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 30 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 34 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 44 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 25 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 21 def url "/v1/#{object_types}" end
Private Instance Methods
data_page()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 63 def data_page filtered_data[offset, limit] end
filtered_data()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 67 def filtered_data filtered_data = data filtered_data = filtered_data.select { |d| d[:active] == active } unless active.nil? filtered_data end
object_types()
click to toggle source
# File lib/stripe_mock/data/list.rb, line 74 def object_types if first_object = data[0] "#{first_object.class.to_s.split('::')[-1].downcase}s" end end