Module: Iord::Iterable

Extended by:
ActiveSupport::Concern
Includes:
Sort
Defined in:
lib/iord/iterable.rb

Instance Method Summary collapse

Methods included from Sort

#create_collection_with_sort, #order_by, #sort_mode

Instance Method Details

#collection_countObject



136
137
138
# File 'lib/iord/iterable.rb', line 136

def collection_count
  @collection_count ||= create_collection.count
end

#iterateObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/iord/iterable.rb', line 140

def iterate
  collection = create_collection
  @pos = pos || collection_count
  if @pos == -1
    @resource = collection.last
    @pos = collection_count - 1
  elsif @pos < collection_count
    @resource = collection.skip(pos).first
  else
    @resource = nil
    @pos = nil
  end
  collection_url_defaults[:pos] = @pos

  if iterate_edition and request.request_method == 'PATCH'
    @pos = 0 if @pos.nil?
    update_resource
    if @resource.save
      flash[:notice] = t('iord.flash.update.notice', model: resource_name)
      redirect_to params[:go_to]
      return
    end
  end
end

#iterate_editionObject



104
105
106
107
108
109
110
# File 'lib/iord/iterable.rb', line 104

def iterate_edition
  if @iterate_edition.nil?
    @iterate_edition = params[:edit] == 'true'
    collection_url_defaults[:edit] = @iterate_edition
  end
  return @iterate_edition
end

#iterate_url(options = {}) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/iord/iterable.rb', line 123

def iterate_url(options = {})
  if options.present?
    if options == true
      options = collection_url_defaults
    else
      options = collection_url_defaults.merge(options)
    end
    return self.public_send "iterate_#{collection_url_method}".to_sym, options
  else
    @iterate_url = self.public_send "iterate_#{collection_url_method}".to_sym
  end
end

#posObject



112
113
114
115
116
117
118
119
120
121
# File 'lib/iord/iterable.rb', line 112

def pos
  if @pos.nil?
    @pos = params[:pos]
    if @pos
      @pos = @pos.to_i
      collection_url_defaults[:pos] = @pos
    end
  end
  return @pos
end