Class: StripeMock::Data::List

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe_mock/data/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ List

Returns a new instance of List.



6
7
8
9
10
# 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]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/stripe_mock/data/list.rb', line 25

def method_missing(method_name, *args, &block)
  hash = to_hash

  if hash.keys.include?(method_name)
    hash[method_name]
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/stripe_mock/data/list.rb', line 4

def data
  @data
end

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/stripe_mock/data/list.rb', line 4

def limit
  @limit
end

#starting_afterObject (readonly)

Returns the value of attribute starting_after.



4
5
6
# File 'lib/stripe_mock/data/list.rb', line 4

def starting_after
  @starting_after
end

Instance Method Details

#has_more?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/stripe_mock/data/list.rb', line 21

def has_more?
  (offset + limit) < data.size
end

#respond_to?(method_name, priv = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/stripe_mock/data/list.rb', line 35

def respond_to?(method_name, priv = false)
  to_hash.keys.include?(method_name) || super
end

#to_hashObject Also known as: to_h



16
17
18
# File 'lib/stripe_mock/data/list.rb', line 16

def to_hash
  { object: "list", data: data_page, url: url, has_more: has_more? }
end

#urlObject



12
13
14
# File 'lib/stripe_mock/data/list.rb', line 12

def url
  "/v1/#{object_types}"
end