Module: IndexView::Implementation
Constant Summary collapse
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #all(*args) ⇒ Object
-
#ascending? ⇒ Boolean
Returns whether or not your index is currently sorted ascended.
-
#columns ⇒ Object
returns a collection of the IndexView::Column objects that were added through the
column
method. -
#descending? ⇒ Boolean
Returns whether or not your index is currently sorted descended.
- #fields_for_search ⇒ Object
- #find(selector, options = {}) ⇒ Object
- #find_options ⇒ Object
- #first(*args) ⇒ Object
-
#initialize(params = { }) ⇒ Object
IndexView objects are initialized with the params of a request.
- #opposite_sort_direction ⇒ Object
-
#paginate ⇒ Object
returns a paginated set of the IndexView’s
target_class
To customize how the objects are paginated - redefinepagination_options
in your class. -
#pagination_options ⇒ Object
Returns a hash of options used to paginate your IndexView’s
target_class
. - #search_term ⇒ Object
- #search_term? ⇒ Boolean
- #sort ⇒ Object
- #sort_direction ⇒ Object
- #sort_term ⇒ Object
-
#sorting?(column_name) ⇒ Boolean
Takes a column name and returns whether or not your index is currently sorted on that column.
- #state ⇒ Object
- #state? ⇒ Boolean
- #table_name ⇒ Object
Methods included from SQLGenerator
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/index_view/implementation.rb', line 9 def params @params end |
Instance Method Details
#all(*args) ⇒ Object
33 34 35 |
# File 'lib/index_view/implementation.rb', line 33 def all(*args) find(:all, *args) end |
#ascending? ⇒ Boolean
Returns whether or not your index is currently sorted ascended.
105 106 107 |
# File 'lib/index_view/implementation.rb', line 105 def ascending? sort_direction == ASC end |
#columns ⇒ Object
returns a collection of the IndexView::Column objects that were added through the column
method
95 96 97 |
# File 'lib/index_view/implementation.rb', line 95 def columns self.class.columns end |
#descending? ⇒ Boolean
Returns whether or not your index is currently sorted descended.
110 111 112 |
# File 'lib/index_view/implementation.rb', line 110 def descending? !ascending? end |
#fields_for_search ⇒ Object
122 123 124 |
# File 'lib/index_view/implementation.rb', line 122 def fields_for_search self.class.fields_for_search end |
#find(selector, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/index_view/implementation.rb', line 24 def find(selector, ={}) case selector when :first, :last, :all target_class.find(selector, .merge()) else target_class.find(selector) end end |
#find_options ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/index_view/implementation.rb', line 41 def { :from => table_name.to_s, :order => sort, :conditions => conditions_sql } end |
#first(*args) ⇒ Object
37 38 39 |
# File 'lib/index_view/implementation.rb', line 37 def first(*args) find(:first, *args) end |
#initialize(params = { }) ⇒ Object
IndexView objects are initialized with the params of a request. See README.rdoc
13 14 15 |
# File 'lib/index_view/implementation.rb', line 13 def initialize(params = { }) @params = params end |
#opposite_sort_direction ⇒ Object
89 90 91 |
# File 'lib/index_view/implementation.rb', line 89 def opposite_sort_direction ascending? ? DESC : ASC end |
#paginate ⇒ Object
returns a paginated set of the IndexView’s target_class
To customize how the objects are paginated - redefine pagination_options
in your class
20 21 22 |
# File 'lib/index_view/implementation.rb', line 20 def paginate target_class.paginate() end |
#pagination_options ⇒ Object
Returns a hash of options used to paginate your IndexView’s target_class
. You can overwrite this in your class to customize pagination.
51 52 53 54 55 56 57 58 59 |
# File 'lib/index_view/implementation.rb', line 51 def { :from => table_name.to_s, :conditions => conditions_sql, :order => sort, :page => @params[:page], :per_page => per_page } end |
#search_term ⇒ Object
61 62 63 |
# File 'lib/index_view/implementation.rb', line 61 def search_term @params[:search] end |
#search_term? ⇒ Boolean
65 66 67 |
# File 'lib/index_view/implementation.rb', line 65 def search_term? search_term && !search_term.blank? ? true : false end |
#sort ⇒ Object
69 70 71 |
# File 'lib/index_view/implementation.rb', line 69 def sort "#{sort_term} #{sort_direction}" + (!secondary_sort_term.blank? ? ", #{secondary_sort_term} #{sort_direction}" : '') end |
#sort_direction ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/index_view/implementation.rb', line 81 def sort_direction if SORT_DIRECTIONS.include?(given_sort_direction) given_sort_direction else raise IndexView::InvalidSort, "#{given_sort_direction} is not a valid sort direction" end end |
#sort_term ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/index_view/implementation.rb', line 73 def sort_term if sort = @params[:sort] sort else default_sort_term.is_a?(Array) ? default_sort_term.join(", ") : default_sort_term end end |
#sorting?(column_name) ⇒ Boolean
Takes a column name and returns whether or not your index is currently sorted on that column.
100 101 102 |
# File 'lib/index_view/implementation.rb', line 100 def sorting?(column_name) sort_term.to_s == column_name.to_s end |
#state ⇒ Object
118 119 120 |
# File 'lib/index_view/implementation.rb', line 118 def state @params[:state] end |
#state? ⇒ Boolean
114 115 116 |
# File 'lib/index_view/implementation.rb', line 114 def state? state && !state.blank? ? true : false end |
#table_name ⇒ Object
126 127 128 |
# File 'lib/index_view/implementation.rb', line 126 def table_name target_class.table_name.to_sym end |