Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vulgata/vulgata_user.rb,
lib/vulgata/vulgatify.rb

Overview

adding vulgatify method to all active record classes

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.vulgata_user(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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 = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#vulgata_admin?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/vulgata/vulgata_user.rb', line 43

def vulgata_admin?
  vulgata_role == :admin
end

#vulgata_localesObject



25
26
27
28
29
30
31
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
# 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?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/vulgata/vulgata_user.rb', line 47

def vulgata_proofreader?
  vulgata_role == :proofreader
end

#vulgata_roleObject



7
8
9
10
11
12
13
# 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) ⇒ Object



15
16
17
18
19
20
21
22
23
# 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?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/vulgata/vulgata_user.rb', line 51

def vulgata_translator?
  vulgata_role == :translator
end