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
- #qualified_const_defined?(klass) ⇒ Boolean
- #qualified_const_get(klass) ⇒ Object
- #random_string(len = 10) ⇒ Object
Instance Method Details
#administrator_group_string ⇒ Object
44 45 46 |
# File 'lib/lockdown/helper.rb', line 44 def administrator_group_string string_name(administrator_group_symbol) end |
#administrator_group_symbol ⇒ Object
48 49 50 |
# File 'lib/lockdown/helper.rb', line 48 def administrator_group_symbol :administrators end |
#camelize(str) ⇒ Object
35 36 37 |
# File 'lib/lockdown/helper.rb', line 35 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
17 18 19 20 21 22 23 |
# File 'lib/lockdown/helper.rb', line 17 def get_string(value) if value.respond_to?(:name) string_name(value.name) else string_name(value) end end |
#get_symbol(value) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/lockdown/helper.rb', line 25 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 |
#qualified_const_defined?(klass) ⇒ Boolean
52 53 54 55 56 57 58 59 |
# File 'lib/lockdown/helper.rb', line 52 def qualified_const_defined?(klass) if klass =~ /::/ namespace, klass = klass.split("::") eval("#{namespace}.const_defined?(#{klass})") if const_defined?(namespace) else const_defined?(klass) end end |
#qualified_const_get(klass) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/lockdown/helper.rb', line 61 def qualified_const_get(klass) if klass =~ /::/ namespace, klass = klass.split("::") eval(namespace).const_get(klass) else const_get(klass) end end |
#random_string(len = 10) ⇒ Object
39 40 41 42 |
# File 'lib/lockdown/helper.rb', line 39 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 |