Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- class Node
- include Mongoid::Document
- include Mongoid::Tree
- # Fields
- #
- field :path, type: String
- field :able, type: Hash, default: {}
- # Validations
- #
- validates :path, :presence => true, :uniqueness => true
- # Callbacks
- #
- after_initialize :setup_abilities
- def setup_abilities
- able.keys.each do |ability|
- self.class.send(:define_method, "is_#{ability}?".to_sym) do
- able[ability]
- end
- self.class.send(:define_method, "is_#{ability}=".to_sym) do |*arg|
- able[ability] = arg
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment