module Eaco::Adapters::ActiveRecord

PostgreSQL 9.4 and up backing store for ACLs.

@see ACL @see PostgresJSONb

Public Class Methods

included(base) click to toggle source

Checks whether the model's data structure fits the ACL persistance requirements.

@param base [Class] your application's model

@return void

# File lib/eaco/adapters/active_record.rb, line 31
def self.included(base)
  Compatibility.new(base).check!

  return unless base.table_exists?

  column = base.columns_hash.fetch('acl', nil)

  unless column
    raise Malformed, "Please define a jsonb column named `acl` on #{base}."
  end

  unless column.type == :json || column.type == :jsonb
    raise Malformed, "The `acl` column on #{base} must be of the jsonb type."
  end
end
strategies() click to toggle source

Currently defined collection extraction strategies.

@return Hash

# File lib/eaco/adapters/active_record.rb, line 19
def self.strategies
  {:pg_jsonb => PostgresJSONb}
end

Public Instance Methods

acl() click to toggle source

@return [ACL] this Resource's ACL.

@see ACL

# File lib/eaco/adapters/active_record.rb, line 52
def acl
  acl = read_attribute(:acl)
  self.class.acl.new(acl)
end
acl=(acl) click to toggle source

Sets the Resource's ACL.

@param acl [ACL] the new ACL to set.

@return [ACL]

@see ACL

# File lib/eaco/adapters/active_record.rb, line 66
def acl=(acl)
  write_attribute :acl, acl.to_hash
end