mikras_utils 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46a6caa587baa5d73d1eee1af5a8cf764fc64e70be223f0b66aae6f1f41c6b91
4
- data.tar.gz: a13096682ea8ec58b36b0154922b7e56fa914e51a756eda8a0f434106e8b1cc2
3
+ metadata.gz: 3ec0c38f1246b0c0f580adc107c6251c70e9600bd08424d05e612c01ae9bd2de
4
+ data.tar.gz: 2a9c833e5475ef646072f4a642309e33616202db3f18d1acc25b46fbb4d10fe2
5
5
  SHA512:
6
- metadata.gz: ac6234c5bcdbc6b2bcf1301c8a6b2c23c4a71a43abaeb47e37c3908126c3d8bfd25bafa439d7ec59a3070f6f5b4706edafc454191a4725d46ab487dad0bf1686
7
- data.tar.gz: 005a114875b9eedbbf2d87d20fa752d8fbde45fd18773bee8d7a7f16373e80d65f0d9a8b9546c3bff67b3c9f429a3119cef8d13e96dbaa916ca6bd19d3f6aa51
6
+ metadata.gz: 264615a11fb958dc628e43e712e069d165640fc87865dd379678aefea9a0d8a16ca4bf0e55b373c53140cf9f53d06ff6c141427d858cb37c5b7300533c525b8d
7
+ data.tar.gz: 87c06e2aa94737f4cababcb7b6154978b974a53b72a79e65a915827a34216179a86665da978a010dac65cfc22106a9d711d6d4ea1349fb07cc4a43a68af2c4d1
data/lib/mikras.rb CHANGED
@@ -1,6 +1,17 @@
1
1
 
2
2
  require 'yaml'
3
3
 
4
+ module Find # Monkey patching standard library
5
+ def self.upfind(dir, file)
6
+ loop do
7
+ return dir if File.exist? File.join(dir, file)
8
+ return nil if dir == "/"
9
+ dir = File.dirname(dir)
10
+ end
11
+ return nil
12
+ end
13
+ end
14
+
4
15
  module Prick
5
16
  # FIXME Hardcoded to avoid dragging in the whole prick environment. Should be
6
17
  # kept in sync with Prick::PRICK_STATE_FILE
@@ -8,13 +19,20 @@ module Prick
8
19
  # TODO: Make prick.rb includable
9
20
  #
10
21
  PRICK_STATE_FILE = ".prick.state.yml"
22
+ PRICK_DIR = Find.upfind(Dir.getwd, PRICK_STATE_FILE)
23
+ PRICK_STATE_PATH = PRICK_DIR && File.join(PRICK_DIR, PRICK_STATE_FILE)
11
24
  end
12
25
 
13
26
  module Mikras
27
+ MIKRAS_LIBDIR = Prick::PRICK_DIR && File.join(Prick::PRICK_DIR, "lib")
28
+
29
+ # Add project-dir/lib to search path
30
+ $LOAD_PATH.unshift MIKRAS_LIBDIR if MIKRAS_LIBDIR
31
+
14
32
  # Find database/username. Called from scripts that may take a database and an
15
33
  # username argument. If the arguments are absent, the database/username is
16
34
  # initialized using the PRICK_DATABASE and PRICK_USERNAME environment
17
- # variables, and if they are also absent, the PRICK_STATE_FILE is read. If
35
+ # variables and if they are also absent, the PRICK_STATE_FILE is read. If
18
36
  # everything fails, the user's username is used as the database and username
19
37
  #
20
38
  def self.credentials(database_argument, username_argument = nil)
@@ -25,8 +43,8 @@ module Mikras
25
43
  database = ENV['PRICK_DATABASE']
26
44
  username = username_argument || ENV['PRICK_USERNAME'] || database
27
45
  else
28
- if File.exist?(Prick::PRICK_STATE_FILE)
29
- prick_state = YAML.load(IO.read Prick::PRICK_STATE_FILE)
46
+ if Prick::PRICK_STATE_PATH
47
+ prick_state = YAML.load(IO.read Prick::PRICK_STATE_PATH)
30
48
  database = prick_state["database"]
31
49
  username = prick_state["username"]
32
50
  else
@@ -33,12 +33,13 @@ module MkAcl
33
33
  insert into acl_portal.acl_tables (
34
34
  schema_name, table_name, domain,
35
35
  parent_schema_name, parent_table_name, parent_link_field,
36
- acl_link_fields, acl)
36
+ triggers, acl_link_fields, acl)
37
37
  values (
38
38
  '#{app_schema}', '#{table}', #{conn.quote_value(table.domain)},
39
39
  #{PgConn.quote_value(table.parent && table.app_schema)},
40
40
  #{PgConn.quote_value(table.parent)},
41
41
  #{PgConn.quote_value(table.parent_link_field)},
42
+ #{table.triggers},
42
43
  #{PgConn.quote_value(table.references.values.map(&:last), elem_type: 'text')},
43
44
  #{table.acl || 'false'})
44
45
  returning id as "table_id"
@@ -44,10 +44,11 @@ module MkAcl
44
44
 
45
45
  def parse_tables(spec, tables)
46
46
  for table_name, actions in tables
47
- acl = actions.key?(:acl) ? actions.delete(:acl) : true
48
47
  parent = actions.delete(:parent)
49
48
  domain = actions.delete(:domain)
50
- table = Table.new(spec, table_name, domain, parent, acl)
49
+ triggers = actions.key?(:triggers) ? actions.delete(:triggers) : true
50
+ acl = actions.key?(:acl) ? actions.delete(:acl) : true
51
+ table = Table.new(spec, table_name, domain, parent, triggers, acl)
51
52
  parse_actions(table, actions)
52
53
  end
53
54
  end
@@ -69,6 +69,9 @@ module MkAcl
69
69
  # the analyzer
70
70
  attr_accessor :domain
71
71
 
72
+ # True if the portal object triggers should be active on the table
73
+ attr_accessor :triggers
74
+
72
75
  # SQL to create the ACL for a table. No ACL if false, default ACL if nil
73
76
  attr_accessor :acl
74
77
 
@@ -84,7 +87,7 @@ module MkAcl
84
87
  # Hash from action name to action object
85
88
  attr_reader :actions
86
89
 
87
- def initialize(spec, name, domain, parent_name, acl)
90
+ def initialize(spec, name, domain, parent_name, triggers, acl)
88
91
  @spec = spec
89
92
  @references = {}
90
93
  @name = name.to_s
@@ -93,6 +96,7 @@ module MkAcl
93
96
  @parent_name = parent_name
94
97
  @parent_link_fields = []
95
98
  @domain = domain
99
+ @triggers = triggers
96
100
  @acl = acl
97
101
  @actions = {}
98
102
  @spec.send :attach_table, self
@@ -113,6 +117,7 @@ module MkAcl
113
117
  for action_name in %w(insert select update delete)
114
118
  actions[action_name]&.dump
115
119
  end
120
+ puts "triggers: #{triggers}"
116
121
  case acl
117
122
  when false; puts "acl: false"
118
123
  when true;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MikrasUtils
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikras_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-14 00:00:00.000000000 Z
11
+ date: 2025-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg_conn