Module: Helioth::ModelAdditions::ClassMethods
- Defined in:
- lib/helioth/model_additions.rb
Instance Method Summary collapse
Instance Method Details
#add_role_validation ⇒ Object
28 29 30 |
# File 'lib/helioth/model_additions.rb', line 28 def add_role_validation self.send(:validates, @@role_column.to_sym, inclusion: { in: available_roles, |
#available_roles ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/helioth/model_additions.rb', line 32 def available_roles case @@role_instance when :user roles = DSL.roles.user.map(&:to_s) when :instance roles = DSL.roles.instance.map(&:to_s) else raise "Invalid option #{options} for method #{__method__}" end end |
#has_helioth_role(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/helioth/model_additions.rb', line 8 def has_helioth_role(*args) = args. @@role_column = [:column] || :role @@role_instance = args.first add_role_validation define_method "#{@@role_column}?" do eval("#{@@role_column}.to_sym") end define_method "helioth_role?" do eval("#{@@role_column}?") end define_method "is_#{@@role_column}?" do |arg| eval("self.#{@@role_column}.to_sym") == arg.to_sym end end |