module ActsAsStarable::Starer::InstanceMethods

Public Instance Methods

all_starred(options={}) click to toggle source

Returns the actual records which this instance has starred.

# File lib/acts_as_starable/starer.rb, line 65
def all_starred(options={})
  all_stars(options).collect { |f| f.starable }
end
all_stars(options={}) click to toggle source

Returns the star records related to this instance with the starable included.

# File lib/acts_as_starable/starer.rb, line 60
def all_stars(options={})
  apply_options_to_scope(stars_scoped, options)
end
get_star_from(starable) click to toggle source

Returns a star record for the current instance and starable object.

# File lib/acts_as_starable/starer.rb, line 70
def get_star_from(starable)
  self.stars.for_starable(starable).first
end
star(starable) click to toggle source

Creates a new star record for this instance to star the passed object. Does not allow duplicate records to be created.

# File lib/acts_as_starable/starer.rb, line 20
def star(starable)
  if self != starable
    self.stars.find_or_create_by(starable_id: starable.id, starable_type: parent_class_name(starable))
  end
end
starred?(starable) click to toggle source

Returns true if this instance has starred the object passed as an argument.

# File lib/acts_as_starable/starer.rb, line 34
def starred?(starable)
  self.stars.for_starable(starable).first.present?
end
starred_by_type(starable_type, options={}) click to toggle source

Returns the actual records of a particular type which this record has starred.

# File lib/acts_as_starable/starer.rb, line 55
def starred_by_type(starable_type, options={})
  stars_by_type(starable_type, options).collect { |f| f.starable }
end
stars_by_type(starable_type, options={}) click to toggle source

Returns the star records related to this instance by type.

# File lib/acts_as_starable/starer.rb, line 49
def stars_by_type(starable_type, options={})
  stars_scope = stars_scoped.for_starable_type(starable_type)
  stars_scope = apply_options_to_scope(stars_scope, options)
end
stars_count() click to toggle source

Returns the number of objects this instance has starred.

# File lib/acts_as_starable/starer.rb, line 39
def stars_count
  self.stars.count
end
stars_scoped() click to toggle source

returns the star records to the current instance

# File lib/acts_as_starable/starer.rb, line 44
def stars_scoped
  self.stars.includes(:starable)
end
unstar(starable) click to toggle source

Deletes the star record if it exists.

# File lib/acts_as_starable/starer.rb, line 27
def unstar(starable)
  if star = get_star_from(starable)
    star.destroy
  end
end