Module: Lockdown::Helper
- Included in:
- Lockdown
- Defined in:
- lib/lockdown/helper.rb
Instance Method Summary collapse
- #administrator_group_string ⇒ Object
- #administrator_group_symbol ⇒ Object
- #camelize(str) ⇒ Object
- #class_name_from_file(str) ⇒ Object
-
#convert_reference_name(str_sym) ⇒ Object
If str_sym is a Symbol (:users), return “Users” If str_sym is a String (“Users”), return :users.
- #get_string(value) ⇒ Object
- #get_symbol(value) ⇒ Object
- #random_string(len = 10) ⇒ Object
- #user_class ⇒ Object
- #user_group_class ⇒ Object
- #user_group_id_reference ⇒ Object
- #user_group_model_string ⇒ Object
- #user_groups_hbtm_reference ⇒ Object
- #user_id_reference ⇒ Object
- #user_model_string ⇒ Object
- #users_hbtm_reference ⇒ Object
Instance Method Details
#administrator_group_string ⇒ Object
78 79 80 |
# File 'lib/lockdown/helper.rb', line 78 def administrator_group_string string_name(administrator_group_symbol) end |
#administrator_group_symbol ⇒ Object
82 83 84 |
# File 'lib/lockdown/helper.rb', line 82 def administrator_group_symbol :administrators end |
#camelize(str) ⇒ Object
69 70 71 |
# File 'lib/lockdown/helper.rb', line 69 def camelize(str) str.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end |
#class_name_from_file(str) ⇒ Object
5 6 7 |
# File 'lib/lockdown/helper.rb', line 5 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
11 12 13 14 15 16 17 |
# File 'lib/lockdown/helper.rb', line 11 def convert_reference_name(str_sym) if str_sym.is_a?(Symbol) titleize(str_sym) else str_sym.underscore.tr(' ','_').to_sym end end |
#get_string(value) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/lockdown/helper.rb', line 51 def get_string(value) if value.respond_to?(:name) string_name(value.name) else string_name(value) end end |
#get_symbol(value) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/lockdown/helper.rb', line 59 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
73 74 75 76 |
# File 'lib/lockdown/helper.rb', line 73 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_class ⇒ Object
31 32 33 |
# File 'lib/lockdown/helper.rb', line 31 def user_class eval(user_model_string) end |
#user_group_class ⇒ Object
19 20 21 |
# File 'lib/lockdown/helper.rb', line 19 def user_group_class eval(user_group_model_string) end |
#user_group_id_reference ⇒ Object
27 28 29 |
# File 'lib/lockdown/helper.rb', line 27 def user_group_id_reference user_group_model_string.underscore + "_id" end |
#user_group_model_string ⇒ Object
43 44 45 |
# File 'lib/lockdown/helper.rb', line 43 def user_group_model_string Lockdown.system.fetch(:user_group_model) || "UserGroup" end |
#user_groups_hbtm_reference ⇒ Object
23 24 25 |
# File 'lib/lockdown/helper.rb', line 23 def user_groups_hbtm_reference user_group_model_string.underscore.pluralize.to_sym end |
#user_id_reference ⇒ Object
39 40 41 |
# File 'lib/lockdown/helper.rb', line 39 def user_id_reference user_model_string.underscore + "_id" end |
#user_model_string ⇒ Object
47 48 49 |
# File 'lib/lockdown/helper.rb', line 47 def user_model_string Lockdown.system.fetch(:user_model) || "User" end |
#users_hbtm_reference ⇒ Object
35 36 37 |
# File 'lib/lockdown/helper.rb', line 35 def users_hbtm_reference user_model_string.underscore.pluralize.to_sym end |