Module: TheRole::Api::BaseMethods
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #any_role?(roles_hash = {}) ⇒ Boolean
- #has_role?(section_name, rule_name) ⇒ Boolean
- #has_section?(section_name) ⇒ Boolean
- #moderator?(section_name) ⇒ Boolean
Instance Method Details
#admin? ⇒ Boolean
41 42 43 |
# File 'app/models/concerns/the_role/api/base_methods.rb', line 41 def admin? has_role? 'any_crazy_name', 'any_crazy_name' end |
#any_role?(roles_hash = {}) ⇒ Boolean
26 27 28 29 30 31 32 33 34 |
# File 'app/models/concerns/the_role/api/base_methods.rb', line 26 def any_role? roles_hash = {} roles_hash.each_pair do |section, rules| return false unless[ Array, String, Symbol ].include?(rules.class) return has_role?(section, rules) if [ String, Symbol ].include?(rules.class) rules.each{ |rule| return true if has_role?(section, rule) } end false end |
#has_role?(section_name, rule_name) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/concerns/the_role/api/base_methods.rb', line 12 def has_role? section_name, rule_name hash = role_hash section_name = section_name.to_slug_param(sep: '_') rule_name = rule_name.to_slug_param(sep: '_') return true if hash.try(:[], 'system').try(:[], 'administrator') return true if hash.try(:[], 'moderator').try(:[], section_name) return false unless hash[section_name] return false unless hash[section_name].key? rule_name hash[section_name][rule_name] end |
#has_section?(section_name) ⇒ Boolean
4 5 6 7 8 9 10 |
# File 'app/models/concerns/the_role/api/base_methods.rb', line 4 def has_section? section_name hash = role_hash section_name = section_name.to_slug_param(sep: '_') return true if hash[section_name] false end |
#moderator?(section_name) ⇒ Boolean
36 37 38 39 |
# File 'app/models/concerns/the_role/api/base_methods.rb', line 36 def moderator? section_name section_name = section_name.to_slug_param(sep: '_') has_role? section_name, 'any_crazy_name' end |