Class: Module
- Defined in:
- lib/vresource/module.rb,
lib/ruby_ext/synchronize.rb,
lib/ruby_ext/declarative_cache.rb
Instance Method Summary collapse
- #[](resource_name) ⇒ Object
- #[]=(resource_name, value) ⇒ Object
- #cache_method(*methods) ⇒ Object
- #cache_method_with_params(*methods) ⇒ Object
-
#resource_exist?(resource_name) ⇒ Boolean
TODO2 Cache it and next one.
- #synchronize_all_methods(include_super = false) ⇒ Object
- #synchronize_method(*methods) ⇒ Object
Instance Method Details
#[](resource_name) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/vresource/module.rb', line 11 def [] resource_name self_ancestors_and_namespaces do |klass| if VResource.resource_exist? klass, resource_name return VResource.resource_get(klass, resource_name) end end raise VResource::NotExist, "Resource '#{resource_name}' for Class '#{self.name}' doesn't exist!", caller end |
#[]=(resource_name, value) ⇒ Object
21 22 23 |
# File 'lib/vresource/module.rb', line 21 def []= resource_name, value VResource.resource_set self.name, resource_name, value end |
#cache_method(*methods) ⇒ Object
4 5 6 |
# File 'lib/ruby_ext/declarative_cache.rb', line 4 def cache_method *methods DeclarativeCache.cache_method self, *methods end |
#cache_method_with_params(*methods) ⇒ Object
8 9 10 |
# File 'lib/ruby_ext/declarative_cache.rb', line 8 def cache_method_with_params *methods DeclarativeCache.cache_method_with_params self, *methods end |
#resource_exist?(resource_name) ⇒ Boolean
TODO2 Cache it and next one
3 4 5 6 7 8 |
# File 'lib/vresource/module.rb', line 3 def resource_exist? resource_name self_ancestors_and_namespaces do |klass| return true if VResource.resource_exist? klass, resource_name end return false end |
#synchronize_all_methods(include_super = false) ⇒ Object
20 21 22 23 |
# File 'lib/ruby_ext/synchronize.rb', line 20 def synchronize_all_methods include_super = false methods = self.instance_methods(include_super).collect{|m| m.to_sym} synchronize_method *methods end |
#synchronize_method(*methods) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_ext/synchronize.rb', line 4 def synchronize_method *methods methods.each do |method| als = "sync_#{escape_method(method)}" raise "Can't synchronize the '#{method}' twice!" if instance_methods.include?(als) alias_method als, method script = "\ def #{method} *p, &b @monitor ||= Monitor.new @monitor.synchronize{#{als} *p, &b} end" class_eval script, __FILE__, __LINE__ end end |