active_pg_log 0.1.1 → 0.1.3

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: 54365b3367760d3de57a0bbd6c222902a740d4704ea254281388968689796fec
4
- data.tar.gz: 83abbc93332027947c30ecc858c4cbc138d568ae2dd437a837862c1547a3a010
3
+ metadata.gz: 0f24883a78dd744db11ff610f457bbd424b7265d618fa63d6ee48b31d4fcbac7
4
+ data.tar.gz: 5a347455d97d9019db3b6197d1a11042f328d350cd327ffbdc025d616530d61a
5
5
  SHA512:
6
- metadata.gz: e711ccce1486e792f693753be1865421592ef94f2ce441f3eebfd04ed0b55364cbe7c77d2e027794db5da6d79d6c04806d08c12689e46f41b56fe8419de43ea3
7
- data.tar.gz: bc543af36a6d776cb0b2806327197d150febb68afe463cd8002a390478eae224fe811e6ebd9adc24689277a2a910897fbe1e7b6c3f4cccc455744f7998f40529
6
+ metadata.gz: 219732a497ccbc7f0981ee9c68e5dacd24c66baf26db158924dc8b07fc045858e147ec81aaae95d0f5db81b91f69abc3cadf8c4af7ff3074cbb9f1a873e6ff28
7
+ data.tar.gz: 17e8f49846761a386e3bf767581984b53baf5b72a89df6a3e486c517dd3a2d1976d46b368243a2f50fdaac24eba415865ff1c8dd6be38cb9d43469abd87125ca
data/.gitignore CHANGED
@@ -10,3 +10,6 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  Gemfile.lock
13
+ *.gem
14
+ .travis.yml
15
+ .rspec
data/.travis.yml CHANGED
@@ -4,4 +4,4 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.6.6
7
- before_install: gem install bundler -v 1.17.3
7
+ before_install: gem install bundler -v 2.2.32
data/Gemfile CHANGED
@@ -5,5 +5,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in active_pg_log.gemspec
6
6
  gemspec
7
7
 
8
- gem 'activerecord'
8
+ gem 'pg'
9
+ gem 'rails', '~> 6.1.4.4'
9
10
  gem 'rubocop'
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ActivePgLog
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_pg_log`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ActivePgLog will record all changes made to the class either using ActiveRecord or in the database itself. Generating a new tuple in the log table and ensuring traceability.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The ActivePgLog gem was conceived with the idea of ​​being a simple but flexible log.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,14 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ After performing the previous steps. Go into your project's root directory and type `rails g active_pg_log:install` or `rails g active_pg_log:uninstall` to remove the settings.
26
+
27
+ After executing the above command. Just add the ActivePgLog::ActiveLog module to your class. Example:
28
+
29
+ class Person
30
+ include ActivePgLog::ActiveLog
31
+ attr_accessor :name, :phone
32
+ end
26
33
 
27
34
  ## Development
28
35
 
@@ -32,7 +39,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
39
 
33
40
  ## Contributing
34
41
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_pg_log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/waejl/active_pg_log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
43
 
37
44
  ## License
38
45
 
@@ -40,4 +47,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
47
 
41
48
  ## Code of Conduct
42
49
 
43
- Everyone interacting in the ActivePgLog project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_pg_log/blob/master/CODE_OF_CONDUCT.md).
50
+ Everyone interacting in the ActivePgLog project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/waejl/active_pg_log/blob/master/CODE_OF_CONDUCT.md).
@@ -32,7 +32,9 @@ Gem::Specification.new do |spec|
32
32
  # spec.executables = %w[setup console]
33
33
  spec.require_paths = ['lib']
34
34
 
35
- spec.add_development_dependency 'bundler', '~> 1.17'
35
+ spec.add_development_dependency 'active_record'
36
+ spec.add_development_dependency 'bundler', '~> 2.2.32'
37
+ spec.add_development_dependency 'pg', '~> 1.2.3'
36
38
  spec.add_development_dependency 'rake', '~> 10.0'
37
39
  spec.add_development_dependency 'rspec', '~> 3.0'
38
40
  end
data/bin/console CHANGED
@@ -1,7 +1,41 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "active_pg_log"
3
+ require 'bundler/setup'
4
+ require 'active_pg_log'
5
+ require 'active_record'
6
+
7
+ begin
8
+ ActiveRecord::Base.establish_connection({
9
+ adapter: 'postgresql',
10
+ database: 'active_pg_log',
11
+ min_messages: 'warning',
12
+ host: 'localhost',
13
+ username: 'postgres',
14
+ password: 'password'
15
+ })
16
+ connection = ActiveRecord::Base.connection
17
+ connection.execute('SELECT 1')
18
+ connection.execute('create table if not exists active_pg_log_tables(
19
+ id serial not null,
20
+ name varchar(255)
21
+ );')
22
+ # connection.execute('create database active_pg_log;')
23
+ # connection.reconect!({
24
+ # adapter: 'postgresql',
25
+ # database: 'active_pg_log',
26
+ # min_messages: 'warning',
27
+ # host: 'localhost',
28
+ # username: 'postgres',
29
+ # password: 'password'
30
+ # })
31
+ rescue StandardError => e
32
+ puts '-' * 80
33
+ puts 'Unable to connect to database. Please run:'
34
+ puts
35
+ puts ' createdb pg_audit_log_test'
36
+ puts '-' * 80
37
+ raise e
38
+ end
5
39
 
6
40
  # You can add fixtures and/or initialization code here to make experimenting
7
41
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +44,5 @@ require "active_pg_log"
10
44
  # require "pry"
11
45
  # Pry.start
12
46
 
13
- require "irb"
47
+ require 'irb'
14
48
  IRB.start(__FILE__)
@@ -1,29 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActivePgLog::ActiveLog
4
- def self.included(clazz)
5
- @active_trigger = ActivePgLog::ActiveTrigger.new
3
+ module ActivePgLog
4
+ # ActiveLog doc
5
+ module ActiveLog
6
+ def self.included(clazz)
7
+ @active_trigger = ActivePgLog::ActiveTrigger.new(clazz.connection)
6
8
 
7
- return if @active_trigger.include?("trigger_log_#{clazz.table_name}_insert_update", clazz.table_name)
9
+ return if @active_trigger.include?("trigger_log_#{clazz.table_name}_insert_update", clazz.table_name)
8
10
 
9
- ActiveRecord::Base.connection.execute(create_log_ddl_trigger(clazz))
10
- end
11
+ clazz.connection.execute(create_log_ddl_trigger(clazz))
12
+ end
11
13
 
12
- def disable_log_ddl_trigger
13
- ActiveRecord::Base.connection.execute("drop trigger if exists trigger_log_#{self.class.table_name}_insert_update on #{self.class.table_name} cascade;")
14
- nil
15
- end
14
+ def disable_log_ddl_trigger(clazz)
15
+ clazz.connection.execute("drop trigger if exists trigger_log_#{self.class.table_name}_insert_update on #{self.class.table_name} cascade;")
16
+ nil
17
+ end
16
18
 
17
- def pg_logs
18
- ActivePgLogTable.where(table_name: self.class.table_name)
19
- end
19
+ def pg_logs
20
+ ActivePgLogTable.where(table_name: self.class.table_name)
21
+ end
20
22
 
21
- class << self
22
- def create_log_ddl_trigger(clazz)
23
- %(
23
+ class << self
24
+ def create_log_ddl_trigger(clazz)
25
+ %(
24
26
  drop trigger if exists trigger_log_#{clazz.table_name}_insert_update on #{clazz.table_name} cascade;
25
27
  CREATE TRIGGER trigger_log_#{clazz.table_name}_insert_update after insert or update on #{clazz.table_name} for each row execute procedure public.active_pg_loging();
26
28
  )
29
+ end
27
30
  end
28
31
  end
29
32
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ActivePgLogTable < ActiveRecord::Base
2
4
  end
@@ -1,12 +1,12 @@
1
1
  class ActivePgLog::ActiveTrigger
2
2
  attr_accessor :dados
3
3
 
4
- def initialize
5
- @dados = ActiveRecord::Base.connection.select_all(query)
4
+ def initialize(connection)
5
+ @dados = connection.select_all(query)
6
6
  end
7
7
 
8
8
  def include?(trigger_name, table_name)
9
- return false if @dados.rows.size.zero?
9
+ return false if !defined?(@dados.rows) || @dados.rows.size.zero?
10
10
 
11
11
  @dados.select { |e| e['table_name'] == table_name && e['trigger_name'] == trigger_name }.size.positive?
12
12
  end
data/lib/active_pg_log.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
4
3
  module ActivePgLog
5
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
6
5
  end
7
6
 
7
+ require 'active_record'
8
8
  require 'active_pg_log/active_pg_log_table'
9
9
  require 'active_pg_log/prepare'
10
- require 'active_pg_log/trigger'
10
+ require 'active_pg_log/active_trigger'
11
11
  require 'active_pg_log/active_log'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe ActivePgLog::ActiveLog do
4
+ it 'respond to pg_logs' do
5
+ expect(subject.instance_methods).to include(:pg_logs)
6
+ end
7
+
8
+ it 'respond to disable_log_ddl_trigger' do
9
+ expect(subject.instance_methods).to include(:disable_log_ddl_trigger)
10
+ end
11
+
12
+ it 'respond to create_log_ddl_trigger' do
13
+ expect(subject).to respond_to(:create_log_ddl_trigger)
14
+ end
15
+ end
@@ -1,5 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe ActivePgLog do
2
4
  it 'has a version number' do
3
5
  expect(ActivePgLog::VERSION).not_to be nil
4
6
  end
7
+
8
+ it 'trigger has required' do
9
+ expect(ActivePgLog::ActiveTrigger).to_not be_nil
10
+ end
11
+
12
+ it 'active_log has required' do
13
+ expect(ActivePgLog::ActiveLog).to_not be_nil
14
+ end
5
15
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MyObjectTest < ActiveRecord::Base
4
+ include ActivePgLog::ActiveLog
5
+ end
6
+
7
+ RSpec.describe ActivePgLogTable do
8
+ before do
9
+ MyObjectTest.create(name: 'Test Object')
10
+ end
11
+
12
+ it 'on create test object Log Table is incremented' do
13
+ expect(subject).to count(1)
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_pg_log'
4
+
5
+ class MyObjectTest < ActiveRecord::Base
6
+ include ActivePgLog::ActiveLog
7
+ end
8
+
9
+ RSpec.describe MyObjectTest do
10
+ context 'Include lib' do
11
+ it 'respond_to pg_logs' do
12
+ expect(subject).to respond_to(:pg_logs)
13
+ end
14
+
15
+ it 'respond_to disable_log_ddl_trigger' do
16
+ expect(subject).to respond_to(:disable_log_ddl_trigger)
17
+ end
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,47 @@
1
- require "bundler/setup"
2
- require "active_pg_log"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'active_pg_log'
5
+ require 'active_record'
6
+ require 'pg'
7
+
8
+ begin
9
+ ActiveRecord::Base.establish_connection({
10
+ adapter: 'postgresql',
11
+ database: 'active_pg_log',
12
+ min_messages: 'warning',
13
+ host: 'localhost',
14
+ username: 'postgres'
15
+ })
16
+ connection = ActiveRecord::Base.connection
17
+ connection.execute('SELECT 1')
18
+ connection.execute('create table if not exists my_object_tests(
19
+ id serial not null,
20
+ name varchar(255)
21
+ );')
22
+ # connection.execute('create database active_pg_log;')
23
+ # connection.reconect!({
24
+ # adapter: 'postgresql',
25
+ # database: 'active_pg_log',
26
+ # min_messages: 'warning',
27
+ # host: 'localhost',
28
+ # username: 'postgres',
29
+ # password: 'password'
30
+ # })
31
+ rescue StandardError => e
32
+ puts '-' * 80
33
+ puts 'Unable to connect to database. Please run:'
34
+ puts
35
+ puts ' createdb pg_audit_log_test'
36
+ puts '-' * 80
37
+ raise e
38
+ end
39
+
40
+ ActiveRecord::Base.default_timezone = :local
3
41
 
4
42
  RSpec.configure do |config|
5
43
  # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
44
+ config.example_status_persistence_file_path = '.rspec_status'
7
45
 
8
46
  # Disable RSpec exposing methods globally on `Module` and `main`
9
47
  config.disable_monkey_patching!
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_pg_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wesley Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-05 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_record
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.17'
33
+ version: 2.2.32
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.32
41
+ - !ruby/object:Gem::Dependency
42
+ name: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.3
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
- version: '1.17'
54
+ version: 1.2.3
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -74,11 +102,14 @@ files:
74
102
  - lib/active_pg_log.rb
75
103
  - lib/active_pg_log/active_log.rb
76
104
  - lib/active_pg_log/active_pg_log_table.rb
105
+ - lib/active_pg_log/active_trigger.rb
77
106
  - lib/active_pg_log/prepare.rb
78
- - lib/active_pg_log/trigger.rb
79
107
  - lib/generators/active_pg_log/install_generator.rb
80
108
  - lib/generators/active_pg_log/templates/lib/tasks/active_pg_log.rake
109
+ - spec/active_log_spec.rb
81
110
  - spec/active_pg_log_spec.rb
111
+ - spec/active_pg_log_table_spec.rb
112
+ - spec/my_object_test_spec.rb
82
113
  - spec/spec_helper.rb
83
114
  homepage: https://github.com/waejl/active_pg_log
84
115
  licenses:
@@ -103,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
134
  - !ruby/object:Gem::Version
104
135
  version: '0'
105
136
  requirements: []
106
- rubygems_version: 3.0.6
137
+ rubygems_version: 3.2.32
107
138
  signing_key:
108
139
  specification_version: 4
109
140
  summary: Gem para log de tabelas via banco de dados PostgreSQL sincronizado com ActiveRecord