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



33
34
35
# File 'lib/active_mocker/loaded_mocks.rb', line 33

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)


42
43
44
# File 'lib/active_mocker/loaded_mocks.rb', line 42

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



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

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



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

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

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

Returns:



70
71
72
# File 'lib/active_mocker/loaded_mocks.rb', line 70

def mocks
  hash.values
end

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

or of mock object.

Parameters:

Returns:



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

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