module Rolistic::ClassMethods

Public Instance Methods

abilities_for(name) click to toggle source
# File lib/rolistic/class_methods.rb, line 31
def abilities_for(name)
  abilities_map.fetch(name) { [] }
end
abilities_for_trait(trait) click to toggle source
# File lib/rolistic/class_methods.rb, line 35
def abilities_for_trait(trait)
  traits_map.fetch(trait) { abilities_for(trait) }
end
abilities_map() click to toggle source
# File lib/rolistic/class_methods.rb, line 21
def abilities_map
  return @abilities_map if defined?(@abilities_map)
  @abilities_map = {}
end
add_role(name, *traits_and_abilities, **options)
Alias for: role
add_trait(trait, abilities)
Alias for: trait
available() click to toggle source
# File lib/rolistic/class_methods.rb, line 62
def available
  abilities_map.keys
end
default() click to toggle source
# File lib/rolistic/class_methods.rb, line 58
def default
  @default if defined?(@default)
end
dump(role) click to toggle source
# File lib/rolistic/class_methods.rb, line 13
def dump(role)
  case role
  when String, Symbol then role.to_s
  when self
    role.to_s unless role.default?
  end
end
load(raw) click to toggle source
# File lib/rolistic/class_methods.rb, line 3
def load(raw)
  case raw
  when self then raw
  when String, Symbol
    new(raw) unless raw.blank?
  else
    new
  end
end
role(name, *traits_and_abilities, **options) click to toggle source
# File lib/rolistic/class_methods.rb, line 44
def role(name, *traits_and_abilities, **options)
  abilities = traits_and_abilities.reduce([]) do |m, t_or_a|
    case t_or_a
    when :everything then Everything
    when Symbol then m + abilities_for_trait(t_or_a)
    when Array then m + t_or_a
    else t_or_a
    end
  end
  abilities_map[name] = abilities
  @default = name if options[:default]
end
Also aliased as: add_role
trait(trait, abilities) click to toggle source
# File lib/rolistic/class_methods.rb, line 39
def trait(trait, abilities)
  traits_map[trait] = abilities
end
Also aliased as: add_trait
traits_map() click to toggle source
# File lib/rolistic/class_methods.rb, line 26
def traits_map
  return @traits_map if defined?(@traits_map)
  @traits_map = {}
end