tidus 1.2.2 → 1.2.4

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: 29d39c2d81b16104dda3be65f20f3978d6ad3d41072a342c1ffbe6468ee97303
4
- data.tar.gz: 99ff886d74e9d9ba9dfb57f621c52d43860ee11e5a82356c24ff34ef0fd005b1
3
+ metadata.gz: 1ab6c8984ca856fa25dbb98b938fa15e0cbc7adbaf7933ad99ad42a27bd12ac1
4
+ data.tar.gz: 637691557e333d4517bd9b1bb68a2e0ea2a0c4836b214afd785c3faea1fa4de9
5
5
  SHA512:
6
- metadata.gz: 6b97785ea704e743e32527f93cfd0fa76a0179d341629c8130eeee9aac3e68d3ec5d16f7fce835ea7715f435f6927d45ee5d1d83cd9cc7020ff220d76463f09c
7
- data.tar.gz: bd9d2a5e831d4048aec31bdd392898e926ec9bc6db70cab9a314764cdf9cbd58ba1a5e74cbb69f6477d3b60ddaf0beef5dfdf3b2a8701f7a24a08eeb880df3cc
6
+ metadata.gz: d55046ce42f820775c03b6a86c2785260910fbea9ec6385643ea3ec69c365e784990cd0d5959e126857b5eb394852cf51341c9e71f30116007d6d1fe9b997713
7
+ data.tar.gz: 684b00ba589772505f7237f32a12fd3f17e503d705bed9ec7bf3a8dfee2f3b6597780a69979d6e269fa5d7f6aabdef1a28635a48d0021e99bba8ebff15e7beba
data/lib/tasks/views.rake CHANGED
@@ -4,7 +4,7 @@ skip_tables = [
4
4
  ]
5
5
 
6
6
  namespace :db do
7
- desc "Clears all the views which are currently existing"
7
+ desc 'Clears all the views which are currently existing'
8
8
  task :clear_views do
9
9
  Rails.application.eager_load! if defined?(Rails)
10
10
 
@@ -17,7 +17,7 @@ namespace :db do
17
17
  end
18
18
  end
19
19
 
20
- desc "Generates all the views for the models"
20
+ desc 'Generates all the views for the models'
21
21
  task :generate_views do
22
22
  Rails.application.eager_load! if defined?(Rails)
23
23
 
@@ -33,13 +33,13 @@ namespace :db do
33
33
  end
34
34
  end
35
35
 
36
- Rake::Task["db:migrate"].enhance ["db:clear_views"]
37
- Rake::Task["db:rollback"].enhance ["db:clear_views"]
36
+ Rake::Task['db:migrate'].enhance ['db:clear_views']
37
+ Rake::Task['db:rollback'].enhance ['db:clear_views']
38
38
 
39
- Rake::Task["db:migrate"].enhance do
40
- Rake::Task["db:generate_views"].invoke
39
+ Rake::Task['db:migrate'].enhance do
40
+ Rake::Task['db:generate_views'].invoke
41
41
  end
42
42
 
43
- Rake::Task["db:rollback"].enhance do
44
- Rake::Task["db:generate_views"].invoke
43
+ Rake::Task['db:rollback'].enhance do
44
+ Rake::Task['db:generate_views'].invoke
45
45
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Tidus
4
4
  module Anonymization
5
+
5
6
  include Tidus::Query
6
7
 
7
8
  def skip_anonymization
@@ -13,7 +14,7 @@ module Tidus
13
14
  end
14
15
 
15
16
  def view_postfix
16
- @view_postfix || "anonymized"
17
+ @view_postfix || 'anonymized'
17
18
  end
18
19
 
19
20
  def view_postfix=(val)
@@ -30,9 +31,10 @@ module Tidus
30
31
 
31
32
  def view_columns
32
33
  @view_columns ||= {}
33
- default_view_columns.merge(@view_columns)
34
- .map{ |k,v| ["#{v} AS #{k}"] }
35
- .flatten
34
+ default_view_columns
35
+ .merge(@view_columns)
36
+ .map { |k, v| ["#{v} AS #{k}"] }
37
+ .flatten
36
38
  end
37
39
 
38
40
  def default_view_columns
@@ -49,8 +51,8 @@ module Tidus
49
51
  options = attributes.extract_options!.dup
50
52
  columns = attributes - [options]
51
53
 
52
- raise ArgumentError, "Must have at least one attribute" if attributes.empty?
53
- raise ArgumentError, "Must have a strategy" if options[:strategy].blank?
54
+ raise ArgumentError.new('Must have at least one attribute') if attributes.empty?
55
+ raise ArgumentError.new('Must have a strategy') if options[:strategy].blank?
54
56
 
55
57
  columns.each do |column|
56
58
  key = options[:strategy].to_s.camelize
@@ -62,14 +64,14 @@ module Tidus
62
64
  klass = const_get("Tidus::#{key}Anonymizer")
63
65
  end
64
66
  rescue NameError
65
- raise ArgumentError, "Unknown anonymizer: '#{key}'"
67
+ raise ArgumentError.new("Unknown anonymizer: '#{key}'")
66
68
  end
67
69
 
68
70
  @view_columns[column.to_sym] = klass.anonymize(table_name, column, options)
69
71
  end
70
72
  end
71
73
 
72
- end
74
+ end
73
75
  end
74
76
 
75
- ActiveRecord::Base.extend Tidus::Anonymization
77
+ ActiveRecord::Base.extend Tidus::Anonymization
data/lib/tidus/query.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Tidus
4
4
  module Query
5
+
5
6
  def create_view_query_part
6
7
  case connection.instance_values['config'][:adapter].to_s.downcase
7
8
  when 'postgresql'
@@ -15,8 +16,8 @@ module Tidus
15
16
 
16
17
  def create_query
17
18
  "#{create_view_query_part} #{view_name} AS " +
18
- "SELECT #{view_columns.join(', ')} " +
19
- "FROM #{table_name}"
19
+ "SELECT #{view_columns.join(', ')} " +
20
+ "FROM #{table_name}"
20
21
  end
21
22
 
22
23
  def create_view
@@ -34,5 +35,6 @@ module Tidus
34
35
  def clear_view
35
36
  connection.execute(clear_query)
36
37
  end
38
+
37
39
  end
38
40
  end
@@ -2,8 +2,9 @@
2
2
 
3
3
  module Tidus
4
4
  class BaseSelector
5
+
5
6
  def self.anonymize(table_name, column_name, options = {})
6
- adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
7
+ adapter = ActiveRecord::Base.connection.instance_values['config'][:adapter]
7
8
 
8
9
  begin
9
10
  klass = Kernel.const_get("Tidus::#{adapter.camelize}::#{self.name.demodulize}")
@@ -11,7 +12,12 @@ module Tidus
11
12
  rescue NameError
12
13
  raise "#{self.name} not implemented for #{adapter}"
13
14
  end
14
-
15
+ rescue ActiveRecord::ConnectionNotEstablished
16
+ # Do nothing here.
17
+ # If the connection cannot be established this cannot be run in a migration
18
+ # and will fail there.
19
+ # For all other cases it does not matter, since the return value of anonymize is not used.
15
20
  end
21
+
16
22
  end
17
23
  end
data/lib/tidus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tidus
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.4"
3
3
  end
data/lib/tidus.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "rake"
4
- require "active_record"
3
+ require 'rake'
4
+ require 'active_record'
5
5
 
6
- require "tidus/version"
7
- require "tidus/query"
8
- require "tidus/anonymization"
9
- require "tidus/strategies/base_selector"
6
+ require 'tidus/version'
7
+ require 'tidus/query'
8
+ require 'tidus/anonymization'
9
+ require 'tidus/strategies/base_selector'
10
10
  Dir["#{File.dirname(__FILE__)}/tidus/strategies/**/*.rb"].each { |f| require f }
11
11
 
12
- load "active_record/railties/databases.rake" if defined?(Rails)
13
- load "tasks/views.rake"
12
+ load 'active_record/railties/databases.rake' if defined?(Rails)
13
+ load 'tasks/views.rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tidus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-15 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake