Module: Eaco::Adapters::ActiveRecord

Defined in:
lib/eaco/adapters/active_record.rb,
lib/eaco/adapters/active_record/compatibility.rb,
lib/eaco/adapters/active_record/postgres_jsonb.rb,
lib/eaco/adapters/active_record/compatibility/v32.rb,
lib/eaco/adapters/active_record/compatibility/v40.rb,
lib/eaco/adapters/active_record/compatibility/v41.rb,
lib/eaco/adapters/active_record/compatibility/v42.rb,
lib/eaco/adapters/active_record/compatibility/v50.rb,
lib/eaco/adapters/active_record/compatibility/v51.rb,
lib/eaco/adapters/active_record/compatibility/scoped.rb,
lib/eaco/adapters/active_record/compatibility/sanitized.rb

Overview

PostgreSQL 9.4 and up backing store for ACLs.

Defined Under Namespace

Modules: PostgresJSONb Classes: Compatibility

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

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

Parameters:

  • base (Class)

    your application's model

Returns:

  • void


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

.strategiesObject

Currently defined collection extraction strategies.

Returns:

  • Hash


19
20
21
# File 'lib/eaco/adapters/active_record.rb', line 19

def self.strategies
  {:pg_jsonb => PostgresJSONb}
end

Instance Method Details

#aclACL

Returns this Resource's ACL.

Returns:

  • (ACL)

    this Resource's ACL.

See Also:


52
53
54
55
# File 'lib/eaco/adapters/active_record.rb', line 52

def acl
  acl = read_attribute(:acl)
  self.class.acl.new(acl)
end

#acl=(acl) ⇒ ACL

Sets the Resource's ACL.

Parameters:

  • acl (ACL)

    the new ACL to set.

Returns:

See Also:


66
67
68
# File 'lib/eaco/adapters/active_record.rb', line 66

def acl=(acl)
  write_attribute :acl, acl.to_hash
end