Class: Catche::ResourceLoader
- Inherits:
-
Object
- Object
- Catche::ResourceLoader
- Defined in:
- lib/catche/resource_loader.rb
Class Method Summary collapse
- .exists?(context, name) ⇒ Boolean
-
.fetch(context, *names) ⇒ Object
Fetches resources in the given context, for example a controller.
- .fetch_one(context, name) ⇒ Object
Class Method Details
.exists?(context, name) ⇒ Boolean
29 30 31 |
# File 'lib/catche/resource_loader.rb', line 29 def exists?(context, name) fetch_one(context, name).present? end |
.fetch(context, *names) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/catche/resource_loader.rb', line 9 def fetch(context, *names) names.collect do |name| if resource = context.instance_variable_get("@#{name}") resource elsif context.respond_to?(name) begin context.send(name) rescue nil end else nil end end.compact end |
.fetch_one(context, name) ⇒ Object
25 26 27 |
# File 'lib/catche/resource_loader.rb', line 25 def fetch_one(context, name) fetch(context, name).first end |