Module: Lockdown::Helper

Included in:
Lockdown
Defined in:
lib/lockdown/helper.rb

Instance Method Summary collapse

Instance Method Details

#administrator_group_stringObject



68
69
70
# File 'lib/lockdown/helper.rb', line 68

def administrator_group_string
  string_name(administrator_group_symbol)
end

#administrator_group_symbolObject



72
73
74
# File 'lib/lockdown/helper.rb', line 72

def administrator_group_symbol
  :administrators
end

#camelize(str) ⇒ Object



59
60
61
# File 'lib/lockdown/helper.rb', line 59

def camelize(str)
  str.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

#class_name_from_file(str) ⇒ Object



3
4
5
# File 'lib/lockdown/helper.rb', line 3

def class_name_from_file(str)
  str.split(".")[0].split("/").collect{|s| camelize(s) }.join("::")
end

#convert_reference_name(str_sym) ⇒ Object

If str_sym is a Symbol (:users), return “Users” If str_sym is a String (“Users”), return :users



9
10
11
12
13
14
15
# File 'lib/lockdown/helper.rb', line 9

def convert_reference_name(str_sym)
  if str_sym.is_a?(Symbol)
    titleize(str_sym)
  else
    underscore(str_sym).tr(' ','_').to_sym
  end
end

#get_string(value) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/lockdown/helper.rb', line 41

def get_string(value)
  if value.respond_to?(:name)
    string_name(value.name)
  else
    string_name(value)
  end
end

#get_symbol(value) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/lockdown/helper.rb', line 49

def get_symbol(value)
  if value.respond_to?(:name)
    symbol_name(value.name)
  elsif value.is_a?(String)
    symbol_name(value)
  else
    value
  end
end

#random_string(len = 10) ⇒ Object



63
64
65
66
# File 'lib/lockdown/helper.rb', line 63

def random_string(len = 10)
  chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
  Array.new(len){||chars[rand(chars.size)]}.join
end

#user_classObject



29
30
31
# File 'lib/lockdown/helper.rb', line 29

def user_class
  eval(Lockdown::System.fetch(:user_model))
end

#user_group_classObject



17
18
19
# File 'lib/lockdown/helper.rb', line 17

def user_group_class
  eval(Lockdown::System.fetch(:user_group_model))
end

#user_group_id_referenceObject



25
26
27
# File 'lib/lockdown/helper.rb', line 25

def user_group_id_reference
  underscore(Lockdown::System.fetch(:user_group_model)) + "_id"
end

#user_groups_hbtm_referenceObject



21
22
23
# File 'lib/lockdown/helper.rb', line 21

def user_groups_hbtm_reference
  underscore(Lockdown::System.fetch(:user_group_model)).pluralize.to_sym
end

#user_id_referenceObject



37
38
39
# File 'lib/lockdown/helper.rb', line 37

def user_id_reference
  underscore(Lockdown::System.fetch(:user_model)) + "_id"
end

#users_hbtm_referenceObject



33
34
35
# File 'lib/lockdown/helper.rb', line 33

def users_hbtm_reference
  underscore(Lockdown::System.fetch(:user_model)).pluralize.to_sym
end