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



38
39
40
# File 'lib/active_mocker/loaded_mocks.rb', line 38

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)


47
48
49
# File 'lib/active_mocker/loaded_mocks.rb', line 47

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



62
63
64
# File 'lib/active_mocker/loaded_mocks.rb', line 62

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



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

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

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

Returns:



75
76
77
# File 'lib/active_mocker/loaded_mocks.rb', line 75

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:



54
55
56
# File 'lib/active_mocker/loaded_mocks.rb', line 54

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