Module: Lockdown::Helper
- Included in:
- ControllerInspector::Core, Session
- Defined in:
- lib/lockdown/helper.rb
Instance Method Summary collapse
- #administrator_group_string ⇒ Object
- #administrator_group_symbol ⇒ Object
- #camelize(str) ⇒ Object
-
#convert_reference_name(str_sym) ⇒ Object
If str_sym is a Symbol (:users), give me back “Users” If str_sym is a String (“Users”), give me back :users.
- #random_string(len = 10) ⇒ Object
- #string_name(str_sym) ⇒ Object
- #symbol_name(str_sym) ⇒ Object
- #symbolize(str) ⇒ Object
- #syms_from_names(ary) ⇒ Object
Instance Method Details
#administrator_group_string ⇒ Object
44 45 46 |
# File 'lib/lockdown/helper.rb', line 44 def administrator_group_string string_name(:administrators) 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 |
#convert_reference_name(str_sym) ⇒ Object
If str_sym is a Symbol (:users), give me back “Users” If str_sym is a String (“Users”), give me back :users
Was :to_title_sym for String and :to_title_str for Symbol
15 16 17 18 19 20 21 |
# File 'lib/lockdown/helper.rb', line 15 def convert_reference_name(str_sym) if str_sym.is_a?(Symbol) titleize(str_sym) else underscore(str_sym).tr(' ','_').to_sym 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 |
#string_name(str_sym) ⇒ Object
23 24 25 |
# File 'lib/lockdown/helper.rb', line 23 def string_name(str_sym) str_sym.is_a?(Symbol) ? convert_reference_name(str_sym) : str_sym end |
#symbol_name(str_sym) ⇒ Object
27 28 29 |
# File 'lib/lockdown/helper.rb', line 27 def symbol_name(str_sym) str_sym.is_a?(String) ? convert_reference_name(str_sym) : str_sym end |
#symbolize(str) ⇒ Object
31 32 33 |
# File 'lib/lockdown/helper.rb', line 31 def symbolize(str) str.downcase.gsub("admin ","admin__").gsub(" ","_").to_sym end |
#syms_from_names(ary) ⇒ Object
3 4 5 6 7 |
# File 'lib/lockdown/helper.rb', line 3 def syms_from_names(ary) rvalue = [] ary.each{|ar| rvalue << symbolize(ar.name)} rvalue end |