Module: Exposure::Finding::ClassMethods
- Defined in:
- lib/exposure/behaviors/finding.rb
Instance Method Summary collapse
-
#build_default_finders(member, nesting) ⇒ Object
:nodoc:.
- #build_default_finders! ⇒ Object
- #build_nested_default_finders!(nesting) ⇒ Object
-
#find(name, options = {}, &block) ⇒ Object
find :person, :with => proc { Person.find_by_permalink(params) } find :people, :with => proc { Person.send(params) } find :dogs, :with => :dogs_adopted_after_date find :dogs do Dog.all end.
Instance Method Details
#build_default_finders(member, nesting) ⇒ Object
:nodoc:
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/exposure/behaviors/finding.rb', line 50 def build_default_finders(member, nesting) #:nodoc: finders = self::const_set(:DefaultFinders, { self.resource_name.intern => proc { [:find, params[:id] ] }, self.resources_name.intern => proc { [:all] } }) nesting.each do |association_name| finders[association_name.to_s.singularize.to_sym] = proc { [:find, params[:"#{association_name.to_s.singularize}_id"]] } finders[association_name] = proc { [ :all ] } end end |
#build_default_finders! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/exposure/behaviors/finding.rb', line 25 def build_default_finders! if nesting = @_exposed_resource_options[:nested] self.build_nested_default_finders!(nesting) return end self.parent_model = self.resource_name.camelize.constantize build_default_finders(self.resource_name, []) self.member_nesting = [ [self.resource_name.to_sym] ] self.collection_nesting = [ [self.resources_name.to_sym] ] end |
#build_nested_default_finders!(nesting) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/exposure/behaviors/finding.rb', line 37 def build_nested_default_finders!(nesting) nesting = nesting.clone self.parent_model = nesting.first.to_s.singularize.camelize.constantize build_default_finders(self.resources_name, nesting) nesting.collect! {|sym| [sym.to_s.singularize.to_sym, sym]} self.member_nesting = nesting + [ [self.resource_name.to_sym, self.resources_name.to_sym] ] self.collection_nesting = nesting + [ [self.resources_name.to_sym, self.resources_name.to_sym] ] end |
#find(name, options = {}, &block) ⇒ Object
find :person, :with => proc { Person.find_by_permalink(params) } find :people, :with => proc { Person.send(params) } find :dogs, :with => :dogs_adopted_after_date find :dogs do
Dog.all
end
valid options are
:with
:only (unimplemented)
:except (unimplemented)
20 21 22 23 |
# File 'lib/exposure/behaviors/finding.rb', line 20 def find(name, = {}, &block) [:with] ||= block self.const_get(:Finders)[name] = [:with] end |