Class: ActiveMocker::LoadedMocks::Collection
- Inherits:
-
Object
- Object
- ActiveMocker::LoadedMocks::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/active_mocker/loaded_mocks.rb
Instance Method Summary collapse
-
#delete_all ⇒ NilClass
Calls #delete_all for all mocks globally, which removes all records that were saved or created.
-
#except(*args) ⇒ Object
Input ActiveRecord Model Name as String or Symbol and it returns everything but that ActiveMock equivalent class.
-
#find(item) ⇒ Object
Input ActiveRecord Model Name as String or Symbol returns ActiveMock equivalent class.
-
#initialize(hash = {}) ⇒ Collection
constructor
A new instance of Collection.
- #mocks ⇒ Array<ActiveMocker::Mock> (also: #values)
-
#slice(*args) ⇒ ActiveMocker::LoadedMocks::Collection
or of mock object.
Constructor Details
#initialize(hash = {}) ⇒ Collection
Returns a new instance of Collection.
40 41 42 |
# File 'lib/active_mocker/loaded_mocks.rb', line 40 def initialize(hash = {}) @hash = Hash[hash] end |
Instance Method Details
#delete_all ⇒ NilClass
Calls #delete_all for all mocks globally, which removes all records that were saved or created.
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]
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
72 73 74 |
# File 'lib/active_mocker/loaded_mocks.rb', line 72 def find(item) slice(item).mocks.first end |
#mocks ⇒ Array<ActiveMocker::Mock> Also known as: values
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.
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 |