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_groups_hbtm_reference ⇒ Object
- #user_id_reference ⇒ Object
- #users_hbtm_reference ⇒ Object
Instance Method Details
#administrator_group_string ⇒ Object
68 69 70 |
# File 'lib/lockdown/helper.rb', line 68 def administrator_group_string string_name(administrator_group_symbol) end |
#administrator_group_symbol ⇒ Object
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_class ⇒ Object
29 30 31 |
# File 'lib/lockdown/helper.rb', line 29 def user_class eval(Lockdown::System.fetch(:user_model)) end |
#user_group_class ⇒ Object
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_reference ⇒ Object
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_reference ⇒ Object
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 |