class ActiveRecord::Base

adding vulgata_user method to all active record classes

adding vulgatify method to all active record classes

Public Class Methods

vulgata_user(options = {}) click to toggle source
# File lib/vulgata/vulgata_user.rb, line 3
def self.vulgata_user(options = {})
  has_one :vulgata_role_object, class_name: "Vulgata::UserRole", as: :user
  has_many :vulgata_locale_objects, class_name: "Vulgata::UserLocale", as: :user

  def vulgata_role
    if self.vulgata_role_object && self.vulgata_role_object.role
      return self.vulgata_role_object.role.to_sym
    end
    
    nil
  end

  def vulgata_role=(role)
    if role.nil?
      self.vulgata_role_object.destroy
    else
      self.vulgata_role_object = Vulgata::UserRole.new unless self.vulgata_role_object
      self.vulgata_role_object.role = role
      self.vulgata_role_object.save
    end
  end

  def vulgata_locales
    if self.vulgata_locale_objects
      return self.vulgata_locale_objects.map { |o| o.locale.to_sym }
    end
    
    nil
  end

  def vulgata_locales=(locales)
    self.vulgata_locale_objects.each do |o|
      o.destroy
    end

    locales.each do |locale|
      self.vulgata_locale_objects << Vulgata::UserLocale.new(user: self, locale: locale)
    end
  end

  def vulgata_admin?
    vulgata_role == :admin
  end

  def vulgata_proofreader?
    vulgata_role == :proofreader
  end

  def vulgata_translator?
    vulgata_role == :translator
  end

end
vulgatify(options = {}) click to toggle source
# File lib/vulgata/vulgatify.rb, line 3
def self.vulgatify(options = {})
  include VulgataMethods
  include VulgataCallbacks

  self.vlg_priority = options[:priority] || Vulgata.configuration.deafult_priority
  self.vlg_strategy = options[:strategy] || Vulgata.configuration.deafult_strategy

  self.vlg_after_translated = options[:after_translated]
  self.vlg_after_approved = options[:after_approved]
  self.vlg_preprocess_setter = options[:preproccess_setter]
  self.vlg_preprocess_getter = options[:preproccess_getter]

  self.vlg_context_path = options[:context_path]
  self.vlg_context_path_param = options[:context_path_param]

  Vulgata::Helpers.add_translating_class self
end

Public Instance Methods

vulgata_admin?() click to toggle source
# File lib/vulgata/vulgata_user.rb, line 43
def vulgata_admin?
  vulgata_role == :admin
end
vulgata_locales() click to toggle source
# File lib/vulgata/vulgata_user.rb, line 25
def vulgata_locales
  if self.vulgata_locale_objects
    return self.vulgata_locale_objects.map { |o| o.locale.to_sym }
  end
  
  nil
end
vulgata_locales=(locales) click to toggle source
# File lib/vulgata/vulgata_user.rb, line 33
def vulgata_locales=(locales)
  self.vulgata_locale_objects.each do |o|
    o.destroy
  end

  locales.each do |locale|
    self.vulgata_locale_objects << Vulgata::UserLocale.new(user: self, locale: locale)
  end
end
vulgata_proofreader?() click to toggle source
# File lib/vulgata/vulgata_user.rb, line 47
def vulgata_proofreader?
  vulgata_role == :proofreader
end
vulgata_role() click to toggle source
# File lib/vulgata/vulgata_user.rb, line 7
def vulgata_role
  if self.vulgata_role_object && self.vulgata_role_object.role
    return self.vulgata_role_object.role.to_sym
  end
  
  nil
end
vulgata_role=(role) click to toggle source
# File lib/vulgata/vulgata_user.rb, line 15
def vulgata_role=(role)
  if role.nil?
    self.vulgata_role_object.destroy
  else
    self.vulgata_role_object = Vulgata::UserRole.new unless self.vulgata_role_object
    self.vulgata_role_object.role = role
    self.vulgata_role_object.save
  end
end
vulgata_translator?() click to toggle source
# File lib/vulgata/vulgata_user.rb, line 51
def vulgata_translator?
  vulgata_role == :translator
end