class RKit::ActiveRecordUtility::Series

Public Instance Methods

first_of_serie() click to toggle source
# File lib/r_kit/active_record_utility/utilities/series.rb, line 62
def first_of_serie
  following ? following.send(__method__) : self
end
in_a_series?() click to toggle source
# File lib/r_kit/active_record_utility/utilities/series.rb, line 70
def in_a_series?
  following || followed
end
navigation_tag() click to toggle source

# TODO: put default locales keys (“vol” is hard coded here) in cluster # same for the ‘title’ methods before # TODO: the “disabled” link for self doesn’t work yet # in fact, the collection does not use the “self” object, so the singleton_class is lost def pagination_tag

series.collection.decorate.map{ |x|
  if x === self
    x.disabled_pagination_link_to
  else
    x.pagination_link_to
  end
}.reduce(:safe_concat)

end

def pagination_link_to

view.link_to "vol #{ position_in_series }", self, class: :btn

end

def disabled_pagination_link_to

view.content_tag :span, "vol #{ position_in_series }", class: :'btn-disabled'

end

nexts_of_serie() click to toggle source
# File lib/r_kit/active_record_utility/utilities/series.rb, line 74
def nexts_of_serie
  followed ? [self] + followed.send(__method__) : [self]
end
position_in_series() click to toggle source

def series

series_struct if read_attribute(:series)
# @@_active_record_utilities_series[read_attribute(:series)] ||= series_struct if read_attribute(:series)
# TODO: if series changes, or new element added, series must be re-calculated
# maybe pre-calc this in after save

end

def series_struct

OpenStruct.new.tap do |series_struct|
  series_struct.name = read_attribute :series
  series_struct.collection = __class__.series series_struct.name
  series_struct.size = series_struct.collection.count
end

end

# File lib/r_kit/active_record_utility/utilities/series.rb, line 93
def position_in_series
  following ? following.send(__method__) + 1 : 1
end
series() click to toggle source
# File lib/r_kit/active_record_utility/utilities/series.rb, line 66
def series
  first_of_serie.nexts_of_serie if in_a_series?
end
series_title() click to toggle source

TODO: I don’t get this “showcase thing”, we can delete that and just look into the view for the params Or in the collection, to see if the scope is applied (second solution is better) TODO: to make a decision, we need to know if ‘first_of_Series’ scope is applied for that, we need to add behavior to ‘scope’ (ActiveRecord::Scoping::Named::ClassMethods) and, on an instance, to keep the ‘collection where it come from’ intel (?? ennumerable first, etc ??)

# File lib/r_kit/active_record_utility/utilities/series.rb, line 128
def series_title
  "#{ __getobj__.title } <small><i class='no-warp'>(vol #{ position_in_series })</i></small>".html_safe
end
showcase() click to toggle source

TODO: don’t ssems to work in decorated obj

# File lib/r_kit/active_record_utility/utilities/series.rb, line 147
def showcase
  scoped? :firsts_of_series
  # collection_context.then{ |collection| collection.scoped? :firsts_of_series }
end
showcase_title() click to toggle source
# File lib/r_kit/active_record_utility/utilities/series.rb, line 132
def showcase_title
  "#{ __getobj__.title } <small><i class='no-warp'>(#{ series.size } vols)</i></small>".html_safe
end
title(options = {}) click to toggle source

TODO: title don’t work if there is no series cause ‘depend’ stille define the method, but will return nil

# File lib/r_kit/active_record_utility/utilities/series.rb, line 138
def title options = {}
  if showcase
    showcase_title
  else
    series_title
  end
end