Module: ActiveRecord::Acts::Seekable::ClassMethods
- Defined in:
- lib/active_record/acts/seekable.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/active_record/acts/seekable.rb', line 12 def config @config end |
Instance Method Details
#acts_as_seekable(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record/acts/seekable.rb', line 14 def acts_as_seekable( = {}) self.config = { :paginate => false } self.config.update() if .is_a?(Hash) self.config[:paginate] = eval(config[:paginate].to_s) if config[:paginate].is_a?(Symbol) self.config[:paginate] = eval(config[:paginate]) if config[:paginate].is_a?(String) class_eval " include ActiveRecord::Acts::Seekable::ClassMethods\n named_scope :all_records\n named_scope :ordered_by, lambda { |order| { :order => order }}\n EOV\nend\n" |
#seek(params = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_record/acts/seekable.rb', line 26 def seek(params = {}) to_eval = "#{name}.all_records" if !params[:filter] if scope = params[:filter] to_eval = "#{name}.#{params[:filter]}" if scopes.has_key?(scope.to_sym) end if !params[:search].blank? && scopes.has_key?(:search) to_eval << ".search('#{params[:search]}')" end to_eval << ".ordered_by('#{params[:order]}')" if params[:order] if eval("#{name}.method_defined?(:paginate)") && config[:paginate] == true to_eval << ".paginate(:page => params[:page], :per_page => params[:per_page] || 5)" end eval(to_eval) end |