Class: ActiveMocker::LoadedMocks::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/active_mocker/loaded_mocks.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Collection

Returns a new instance of Collection.

Parameters:

  • opts (Hash)

    a customizable set of options



40
41
42
# File 'lib/active_mocker/loaded_mocks.rb', line 40

def initialize(hash = {})
  @hash = Hash[hash]
end

Instance Method Details

#delete_allNilClass

Calls #delete_all for all mocks globally, which removes all records that were saved or created.

Returns:

  • (NilClass)


49
50
51
# File 'lib/active_mocker/loaded_mocks.rb', line 49

def delete_all
  mocks.each(&__method__)
end

#except(*args) ⇒ Object

Input ActiveRecord Model Name as String or Symbol and it returns everything but that ActiveMock equivalent class.

except('User') => [AccountMock, OtherMock]

Parameters:

Returns:

  • ActiveMocker::LoadedMocks::Collection



64
65
66
# File 'lib/active_mocker/loaded_mocks.rb', line 64

def except(*args)
  self.class.new(reject { |k, v| get_item(args, k, v) })
end

#find(item) ⇒ Object

Input ActiveRecord Model Name as String or Symbol returns ActiveMock equivalent class.

find('User') => UserMock

Parameters:

Returns:

  • ActiveMocker::Mock



72
73
74
# File 'lib/active_mocker/loaded_mocks.rb', line 72

def find(item)
  slice(item).mocks.first
end

#mocksArray<ActiveMocker::Mock> Also known as: values

Returns:



77
78
79
# File 'lib/active_mocker/loaded_mocks.rb', line 77

def mocks
  hash.values
end

#slice(*args) ⇒ ActiveMocker::LoadedMocks::Collection

or of mock object.

Parameters:

  • args (Array<Symbol, String, ActiveMocker::Mock>)

    an array of ActiveRecord Model Names as Strings or Symbols

Returns:



56
57
58
# File 'lib/active_mocker/loaded_mocks.rb', line 56

def slice(*args)
  self.class.new(select { |k, v| get_item(args, k, v) })
end