Module: Volt::RepoCache::Util
- Included in:
- Association, Cache, Collection, Model, ModelArray
- Defined in:
- lib/volt/repo_cache/util.rb
Class Method Summary collapse
- .adder(getter) ⇒ Object
- .arrify(object) ⇒ Object
- .creator(getter) ⇒ Object
- .debug(method, line, msg = nil) ⇒ Object
- .friend?(object) ⇒ Boolean
- .friends_only(__method__, caller) ⇒ Object
- .not_yet_implemented(method) ⇒ Object
- .prefix_method(getter, prefix) ⇒ Object
- .remover(getter) ⇒ Object
- .setter(getter) ⇒ Object
- .subclass_responsibility(method) ⇒ Object
- .time(method, line, msg = nil) ⇒ Object
- .unsupported(method) ⇒ Object
Class Method Details
.adder(getter) ⇒ Object
14 15 16 |
# File 'lib/volt/repo_cache/util.rb', line 14 def adder(getter) prefix_method(getter, 'add') end |
.arrify(object) ⇒ Object
26 27 28 |
# File 'lib/volt/repo_cache/util.rb', line 26 def arrify(object) object.respond_to?(:to_a) ? object.to_a : [object] end |
.creator(getter) ⇒ Object
10 11 12 |
# File 'lib/volt/repo_cache/util.rb', line 10 def creator(getter) prefix_method(getter, 'new') end |
.debug(method, line, msg = nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/volt/repo_cache/util.rb', line 60 def debug(method, line, msg = nil) s = ">>> #{self.class.name}##{method}[#{line}] : #{msg}" if RUBY_PLATFORM == 'opal' Volt.logger.debug s else puts s end end |
.friend?(object) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 |
# 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) ⇒ Object
42 43 44 45 46 |
# 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) ⇒ Object
34 35 36 |
# 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) ⇒ Object
22 23 24 |
# File 'lib/volt/repo_cache/util.rb', line 22 def prefix_method(getter, prefix) :"#{prefix}_#{getter.to_s.singularize}" end |
.remover(getter) ⇒ Object
18 19 20 |
# File 'lib/volt/repo_cache/util.rb', line 18 def remover(getter) prefix_method(getter, 'remove') end |
.setter(getter) ⇒ Object
6 7 8 |
# File 'lib/volt/repo_cache/util.rb', line 6 def setter(getter) :"#{getter}=" end |
.subclass_responsibility(method) ⇒ Object
38 39 40 |
# 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) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/volt/repo_cache/util.rb', line 69 def time(method, line, msg = nil) t1 = Time.now r = yield t2 = Time.now debug(method, line, "#{msg} : took #{t2 - t1} seconds") r end |
.unsupported(method) ⇒ Object
30 31 32 |
# File 'lib/volt/repo_cache/util.rb', line 30 def unsupported(method) fail "#{method} is an unsupported operation for #{self.class.name}" end |