Class: MkAcl::Generator::IdFunctions

Inherits:
Object
  • Object
show all
Defined in:
lib/mikras_utils/mkacl/generators/id_functions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator) ⇒ IdFunctions

Returns a new instance of IdFunctions.



15
16
17
18
# File 'lib/mikras_utils/mkacl/generators/id_functions.rb', line 15

def initialize(generator)
  @generator = generator
  @chains = {}
end

Instance Attribute Details

#chainsObject (readonly)

Map from domain table to list of [table, path, links] tuples. The entries describes the SQL link chain from the table to the given domain table (cases, events, or visits)



13
14
15
# File 'lib/mikras_utils/mkacl/generators/id_functions.rb', line 13

def chains
  @chains
end

#generatorObject (readonly)

Returns the value of attribute generator.



7
8
9
# File 'lib/mikras_utils/mkacl/generators/id_functions.rb', line 7

def generator
  @generator
end

Class Method Details

.generate(generator) ⇒ Object



77
# File 'lib/mikras_utils/mkacl/generators/id_functions.rb', line 77

def self.generate(generator) self.new(generator).generate end

Instance Method Details

#generateObject

Generate a set of per-table functions that returns the associated case_id/event_id/vist_id for the given record. The Functions are generated for each table in the spec file (todo read from meta)

app_portal functions:

case_id_of_RECORD(object_id integer)
event_id_of_RECORD(object_id integer)
visit_id_of_RECORD(object_id integer)

‘RECORD’ is substituted with the record name of a table. Record names are the singular name of a table. TODO: Make it plural again

acl_portal functions with a record argument (used in triggers):

case_id_of_RECORD(r record)
event_id_of_RECORD(r record)
visit_id_of_RECORD(r record)

Returns the case, event, or visit id associated with the given record. The record should be an ACL table record type. These functions are used in before insert triggers because it takes a record (eg. NEW) instead of an ID - this saves a lookup

acl_portal general id-of functions:

case_id_of(table varchar, id integer)
event_id_of(table varchar, id integer)
visit_id_of(table varchar, id integer)

These methods are practically as efficient as using the more specialized versions above

Returns null if not found. Note that the record has to exists because we access it to read the foreign keys

TODO: ACL checks so that a user can’t get IDs of other users’ records



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mikras_utils/mkacl/generators/id_functions.rb', line 57

def generate
  # Find chains
  @chains = conn.multimap %(
    select
      dst_table_name as "key",
      src_table_name as "table_name",
      path as "tables",
      links
    from
      meta.chains
    where src_schema_name = '#{app_schema}'
      and dst_schema_name = '#{app_schema}'
      and dst_table_name in (#{conn.quote_values(DOMAIN_TABLES)})
  )

  generate_per_table_id_functions
  generate_general_id_functions
  generate_general_id_of_record_functions
end