class SocialMan::ActionThesaurus

Attributes

action[R]
all_objects[R]
all_subjects[R]
name[R]
objects_prefix[R]
passive_action[R]
passive_undo[R]
subjects_prefix[R]
type[R]
undo[R]

Public Class Methods

new(action_name, options={}) click to toggle source
# File lib/social_man/action_thesaurus.rb, line 19
def initialize(action_name, options={})
  @name = action_name.to_sym
  name = action_name.to_s
  @type = options_or_thesaurus(options, :type) || name.camelize
  @action = options_or_thesaurus(options, :action) || name
  @undo = options_or_thesaurus(options, :undo) || 'un' + name
  @passive_action = options_or_thesaurus(options, :passive_action) || name + 'ed_by'
  @passive_undo = options_or_thesaurus(options, :passive_undo) || 'un' + name + + 'ed_by'
  @subjects_prefix = options_or_thesaurus(options, :subjects_prefix) || name + 'ing_'
  @objects_prefix = options_or_thesaurus(options, :objects_prefix) || name + 'ed_'
  @all_subjects = options_or_thesaurus(options, :all_subjects) || name + 'ers'
  @all_objects = options_or_thesaurus(options, :all_objects) || name + 'ables'
end

Private Class Methods

init_thesaurus() click to toggle source
# File lib/social_man/action_thesaurus.rb, line 49
def init_thesaurus
  thesaurus_array = [
    %w(like unlike liked_by unliked_by liking liked liker likeable),
    %w(star unstar starred_by unstarred_by starring starred starrer starable),
    %w(block unblock blocked_by unblocked_by blocking blocked blockers blockable),
    %w(follow unfollow followed_by unfollowed_by following followed follower followee),
    %w(vote unvote voted_by unvoted_by voting voted voter votable)
  ]

  thesaurus = {}
  thesaurus_array.each do |line|
    thesaurus[line[0].to_sym] = {
      name: line[0].to_sym, 
      type: line[0].camelize,
      action: line[0],
      undo: line[1],
      passive_action: line[2],
      passive_undo: line[3],
      subjects_prefix: line[4] + '_',
      objects_prefix: line[5] + '_',
      all_subjects: line[6].pluralize,
      all_objects: line[7].pluralize
    }
  end

  thesaurus
end
thesaurus() click to toggle source
# File lib/social_man/action_thesaurus.rb, line 45
def thesaurus
  @@thesaurus ||= init_thesaurus
end

Private Instance Methods

fetch_thesaurus(action_name, key) click to toggle source
# File lib/social_man/action_thesaurus.rb, line 39
def fetch_thesaurus(action_name, key)
  action = ActionThesaurus.thesaurus[action_name]
  action.nil? ? nil : action[key]
end
options_or_thesaurus(options, key) click to toggle source
# File lib/social_man/action_thesaurus.rb, line 35
def options_or_thesaurus(options, key)
  options[key].presence || fetch_thesaurus(@name, key)
end