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
11
12
13
14
15
16
# 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 contains_stripe_objects?
    prune_deleted_data
    sort_data
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



31
32
33
34
35
36
37
38
39
# File 'lib/stripe_mock/data/list.rb', line 31

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

#activeObject (readonly)

Returns the value of attribute active.



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

def active
  @active
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#ending_beforeObject (readonly)

Returns the value of attribute ending_before.



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

def ending_before
  @ending_before
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)


27
28
29
# File 'lib/stripe_mock/data/list.rb', line 27

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

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

Returns:

  • (Boolean)


41
42
43
# File 'lib/stripe_mock/data/list.rb', line 41

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

#to_hashObject Also known as: to_h



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

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

#urlObject



18
19
20
# File 'lib/stripe_mock/data/list.rb', line 18

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