module DomainNeutral::SymbolizedClass

Public Instance Methods

flush_cache() click to toggle source

Flushes cache if record is saved

# File lib/domain_neutral/symbolized_class.rb, line 173
def flush_cache
  Rails.cache.delete([self.class.name, symbol_was.to_s])
  Rails.cache.delete([self.class.name, id])
end
is_none_of?(*syms) click to toggle source

Role.admin.is_none_of?(:site_admin, :user_admin)

> true

Role.admin.is_none_of?(:admin, :site_admin)

> false

# File lib/domain_neutral/symbolized_class.rb, line 149
def is_none_of?(*syms)
  !syms.flatten.include?(to_sym)
end
is_one_of?(*syms) click to toggle source

Role.admin.is_one_of?(:admin, :site_admin)

> true

Role.admin.is_one_of?(:site_admin, :user_admin)

> false

# File lib/domain_neutral/symbolized_class.rb, line 141
def is_one_of?(*syms)
  syms.flatten.include?(to_sym)
end
method_missing(method, *args) click to toggle source

Allow to test for a specific role or similar like Role.accountant?

Calls superclass method
# File lib/domain_neutral/symbolized_class.rb, line 154
def method_missing(method, *args)
  if method.to_s =~ /^(\w+)\?$/
    v = self.class.find_by_symbol($1)
    raise NameError unless v
    other = v.to_sym
    self.class.class_eval { define_method(method) { self.to_sym == other }}
    return self.to_sym == other
  end
  super
end
respond_to?(meth, include_private = false) click to toggle source
Calls superclass method
# File lib/domain_neutral/symbolized_class.rb, line 165
def respond_to?(meth, include_private = false) # :nodoc
  if m = /^(\w+)\?$/.match(meth.to_s)
    return true if self.to_sym == m[1].to_sym
  end
  super
end
symbol() click to toggle source

Retrieve symbol

# File lib/domain_neutral/symbolized_class.rb, line 126
def symbol
  @symbol ||= begin
    s = read_attribute(:symbol)
    s && s.to_sym
  end
end
symbol=(name) click to toggle source

Store symbol

# File lib/domain_neutral/symbolized_class.rb, line 121
def symbol=(name)
  write_attribute(:symbol, name.to_s)
end
to_sym() click to toggle source
# File lib/domain_neutral/symbolized_class.rb, line 133
def to_sym
  symbol
end