Class: Agree2::ProxyCollection
- Inherits:
-
Object
- Object
- Agree2::ProxyCollection
- Defined in:
- lib/agree2/proxy_collection.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#singular ⇒ Object
Returns the value of attribute singular.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Explicitly proxy === because the instance method removal above doesn’t catch it.
-
#build(attributes = {}) ⇒ Object
Builds an instance of the record.
-
#create(attributes = {}) ⇒ Object
Builds and saves and instance of the record.
-
#find(id) ⇒ Object
Finds the instance given the id.
-
#initialize(container, path, class_name = nil, values = nil) ⇒ ProxyCollection
constructor
A new instance of ProxyCollection.
-
#proxy_respond_to? ⇒ Object
:nodoc:.
-
#respond_to?(symbol, include_priv = false) ⇒ Boolean
:nodoc:.
Constructor Details
#initialize(container, path, class_name = nil, values = nil) ⇒ ProxyCollection
Returns a new instance of ProxyCollection.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/agree2/proxy_collection.rb', line 7 def initialize(container,path,class_name=nil,values=nil) @container=container @user=(container.is_a?(User) ? container : container.user) @path=path path=~/(\w+)$/ @singular=(class_name||$1.singularize).downcase.classify @klass=eval "Agree2::#{@singular}" if values @target=instantiate_items(values) else reset end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
:nodoc:
69 70 71 72 73 |
# File 'lib/agree2/proxy_collection.rb', line 69 def method_missing(method, *args, &block) #:nodoc: if load_target @target.send(method, *args, &block) end end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/agree2/proxy_collection.rb', line 6 def path @path end |
#singular ⇒ Object
Returns the value of attribute singular.
6 7 8 |
# File 'lib/agree2/proxy_collection.rb', line 6 def singular @singular end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/agree2/proxy_collection.rb', line 6 def user @user end |
Instance Method Details
#===(other) ⇒ Object
Explicitly proxy === because the instance method removal above doesn’t catch it.
42 43 44 45 |
# File 'lib/agree2/proxy_collection.rb', line 42 def ===(other) #:nodoc: load_target other === @target end |
#build(attributes = {}) ⇒ Object
Builds an instance of the record
22 23 24 |
# File 'lib/agree2/proxy_collection.rb', line 22 def build(attributes={}) @klass.new @container,attributes end |
#create(attributes = {}) ⇒ Object
Builds and saves and instance of the record
27 28 29 |
# File 'lib/agree2/proxy_collection.rb', line 27 def create(attributes={}) build(attributes).save end |
#find(id) ⇒ Object
Finds the instance given the id
32 33 34 |
# File 'lib/agree2/proxy_collection.rb', line 32 def find(id) @klass.get @container,id end |
#proxy_respond_to? ⇒ Object
:nodoc:
4 |
# File 'lib/agree2/proxy_collection.rb', line 4 alias_method :proxy_respond_to?, :respond_to? |
#respond_to?(symbol, include_priv = false) ⇒ Boolean
:nodoc:
36 37 38 |
# File 'lib/agree2/proxy_collection.rb', line 36 def respond_to?(symbol, include_priv = false) #:nodoc: proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv)) end |