class ActiveMocker::LoadedMocks::Collection

Attributes

hash[R]

Public Class Methods

new(hash = {}) click to toggle source

@option opts [Hash] hash

# File lib/active_mocker/loaded_mocks.rb, line 40
def initialize(hash = {})
  @hash = Hash[hash]
end

Public Instance Methods

delete_all() click to toggle source

Calls {#delete_all} for all mocks globally, which removes all records that were saved or created. @return [NilClass]

# File lib/active_mocker/loaded_mocks.rb, line 49
def delete_all
  mocks.each(&__method__)
end
except(*args) click to toggle source

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

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

@param [Array<Symbol, String, ActiveMocker::Mock>] args @return ActiveMocker::LoadedMocks::Collection

# 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) click to toggle source

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

find('User') => UserMock

@param [Symbol, String, ActiveMocker::Mock] item @return ActiveMocker::Mock

# File lib/active_mocker/loaded_mocks.rb, line 72
def find(item)
  slice(item).mocks.first
end
mocks() click to toggle source

@return [Array<ActiveMocker::Mock>]

# File lib/active_mocker/loaded_mocks.rb, line 77
def mocks
  hash.values
end
Also aliased as: values
slice(*args) click to toggle source

@param [Array<Symbol, String, ActiveMocker::Mock>] args an array of ActiveRecord Model Names as Strings or Symbols or of mock object. @return [ActiveMocker::LoadedMocks::Collection] returns ActiveMock equivalent class.

# File lib/active_mocker/loaded_mocks.rb, line 56
def slice(*args)
  self.class.new(select { |k, v| get_item(args, k, v) })
end
values()
Alias for: mocks

Private Instance Methods

get_item(args, k, v) click to toggle source
# File lib/active_mocker/loaded_mocks.rb, line 86
def get_item(args, k, v)
  args.map do |e|
    if [:to_str, :to_sym].any? { |i| e.respond_to? i }
      e.to_s == k
    else
      e == v
    end
  end.any? { |a| a }
end