module Volt::RepoCache::Util

Public Instance Methods

adder(getter) click to toggle source
# File lib/volt/repo_cache/util.rb, line 14
def adder(getter)
  prefix_method(getter, 'add')
end
arrify(object) click to toggle source
# File lib/volt/repo_cache/util.rb, line 26
def arrify(object)
  object.respond_to?(:to_a) ? object.to_a : [object]
end
creator(getter) click to toggle source
# File lib/volt/repo_cache/util.rb, line 10
def creator(getter)
  prefix_method(getter, 'new')
end
friend?(object) click to toggle source
# File lib/volt/repo_cache/util.rb, line 48
def friend?(object)
  if object
    if object.is_a?(Volt::Model)
      object.respond_to?(:patched_for_cache?)
    else
      (object.class.name =~ /^Volt::RepoCache/) == 0
    end
  else
    false
  end
end
friends_only(__method__, caller) click to toggle source
# File lib/volt/repo_cache/util.rb, line 42
def friends_only(__method__, caller)
  unless friend?(caller)
    fail "#{self.class.name}##{__method__} for Volt::RepoCache use only, not #{caller.class.name}"
  end
end
not_yet_implemented(method) click to toggle source
# File lib/volt/repo_cache/util.rb, line 34
def not_yet_implemented(method)
  fail "#{method} is not yet implemented for #{self.class.name}"
end
prefix_method(getter, prefix) click to toggle source
# File lib/volt/repo_cache/util.rb, line 22
def prefix_method(getter, prefix)
  :"#{prefix}_#{getter.to_s.singularize}"
end
remover(getter) click to toggle source
# File lib/volt/repo_cache/util.rb, line 18
def remover(getter)
  prefix_method(getter, 'remove')
end
setter(getter) click to toggle source
# File lib/volt/repo_cache/util.rb, line 6
def setter(getter)
  :"#{getter}="
end
subclass_responsibility(method) click to toggle source
# File lib/volt/repo_cache/util.rb, line 38
def subclass_responsibility(method)
  fail "#{method} is responsibility of #{self.class.name}"
end
time(method, line, msg = nil) { || ... } click to toggle source
# File lib/volt/repo_cache/util.rb, line 60
def time(method, line, msg = nil)
  t1 = Time.now
  r = yield
  t2 = Time.now
  debug 1, ->{['nil file', line, method, "#{msg} : took #{t2 - t1} seconds"]}
  r
end
unsupported(method) click to toggle source
# File lib/volt/repo_cache/util.rb, line 30
def unsupported(method)
  fail "#{method} is an unsupported operation for #{self.class.name}"
end