class Object

Public Class Methods

inherited(subclass) click to toggle source
# File lib/wooster/base.rb, line 38
def inherited(subclass)
  Wooster::init_policy(subclass)
  old_inherited(subclass)
end
Also aliased as: old_inherited
old_inherited(subclass)
Alias for: inherited

Public Instance Methods

[](key) click to toggle source
# File lib/wooster/base.rb, line 45
def [](key)
  self.send key
end
define_attribute_methods(*attrs) click to toggle source
# File lib/wooster/base.rb, line 64
def define_attribute_methods(*attrs)
  define_attribute_methods_old(*attrs)
    
  after_find do
    new_attr = Hash[]
    attributes.each {|k,v|
      #if all rules return false and more than one rule returns false -> reject
      succ = true
      default = nil
      self.class.wooster_field[k].read.each{|func|
        succ, value = Wooster.controller_exec(func,self)
        default ||= value
        if(succ)
          break
        end
      }
      if(!succ)
        new_attr[k] = default || self.class.column_defaults[k.to_s]
      end
    }
    attributes.merge! new_attr
  end
  before_create do
    unless Wooster.any_permission?(self.class.wooster_records.create,self)
      raise InvalidCreateError
    end
  end
  before_update do
    unless Wooster.any_permission?(self.class.wooster_records.write,self)
      raise InvalidCreateError
    end
  end
  before_destroy do
    ## XXXX: Hook destroy?
    unless Wooster.any_permission?(self.class.wooster_records.delete,self)
      raise InvalidDeleteError
    end
  end
  before_save do
    changes.each {|field,value|
      if false
        raise InvalidSaveError
      end
    }
  end
end
find_by_sql(sql,binds=[]) click to toggle source
# File lib/wooster/base.rb, line 114
def find_by_sql(sql,binds=[])
  find_by_sql_without_wooster(sql,binds).select{|rec| Wooster.any_permission?(wooster_records.read, rec)   }
end
Also aliased as: find_by_sql_without_wooster
find_by_sql_without_wooster(sql,binds=[])
Alias for: find_by_sql
wooster_wrap() { || ... } click to toggle source
# File lib/wooster/base.rb, line 52
def wooster_wrap
  Thread.current[:wooster_controller] = self
  begin
    yield
  ensure
    Thread.current[:wooster_controller] = nil
  end
end