Class: SurveyGizmo::Collection
- Inherits:
-
Object
- Object
- SurveyGizmo::Collection
show all
- Includes:
- Enumerable
- Defined in:
- lib/survey_gizmo/collection.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
34
35
36
37
|
# File 'lib/survey_gizmo/collection.rb', line 34
def method_missing(meth, *args, &blk)
lazy_load
@collection.send(meth, *args, &blk)
end
|
Instance Method Details
#each ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/survey_gizmo/collection.rb', line 24
def each
lazy_load
if block_given?
@collection.each{ |o| yield(o) }
else
@collection.each
end
end
|
#length ⇒ Object
19
20
21
|
# File 'lib/survey_gizmo/collection.rb', line 19
def length
@array.length
end
|
#model ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/survey_gizmo/collection.rb', line 40
def model
return @model if defined?(@model)
return (@model = options[:target]) if options[:target].is_a?(Class)
name_string = options[:target].is_a?(Symbol) ? ActiveSupport::Inflector.classify(options[:target]) : options[:target]
@model = name_string[/::/] ? Object.const_get?(name_string) : Resource.descendants.detect{ |d| ActiveSupport::Inflector.demodulize(d.name) == name_string }
raise NameError, "#{name_string} is not a descendant of SurveyGizmo::Resource" unless @model
@model
end
|