plok 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/concerns/plok/loggable.rb +17 -0
- data/app/models/log.rb +24 -0
- data/db/migrate/20211008130809_create_plok_logs.rb +16 -0
- data/lib/plok/engine.rb +42 -0
- data/lib/plok/version.rb +1 -1
- data/lib/plok.rb +2 -3
- metadata +37 -7
- data/config/plok.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c83d448013e7832bf4b624c51592b39f336a642b9edf197135792ac4418a63e
|
4
|
+
data.tar.gz: c7ea5c310c9f68f4005b04750bc1bc93696846ec0f8c6b4ec7147c298d978af7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48743033cccfda8512c87be249cf4e1441e47821183aeb95a6fe1451b0a301daff5bbd7c0543f121e9742ac5009f68ae9c3adf74ddf7791ec27ba0fa5c42407a
|
7
|
+
data.tar.gz: 13da11c0ed6a34dda6acae4f9d28a7d3db3cf20f549d2cbfd0365d9e60ebaac7c8f15c8c06e951ea7f545bfee75fdc9d2cade0261fb0c074ac567cecd07cfe9b
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Plok::Loggable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
has_many :logs, as: :loggable, dependent: :nullify
|
6
|
+
end
|
7
|
+
|
8
|
+
def log(message, category = nil, data = {})
|
9
|
+
data = data.permit!.to_h if data.is_a?(ActionController::Parameters)
|
10
|
+
|
11
|
+
logs.create!(
|
12
|
+
content: message,
|
13
|
+
category: category,
|
14
|
+
data: data
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
data/app/models/log.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Log < ActiveRecord::Base
|
2
|
+
belongs_to :loggable, polymorphic: true
|
3
|
+
|
4
|
+
serialize :data, Hash
|
5
|
+
|
6
|
+
# TODO: A file column is currently used in Raamwinkel to link either PDFs or
|
7
|
+
# images to a log message. We'd prefer not use Uploader classes in Plok, so
|
8
|
+
# I'll leave this comment as a reference until assets become available in
|
9
|
+
# Plok.
|
10
|
+
#mount_uploader :file, LogFileUploader
|
11
|
+
|
12
|
+
default_scope { order('created_at DESC, id DESC') }
|
13
|
+
scope :status, -> { where(category: 'status') }
|
14
|
+
|
15
|
+
validate :some_content_present?
|
16
|
+
|
17
|
+
def self.latest
|
18
|
+
Log.first # default_scope sorts in descending order.
|
19
|
+
end
|
20
|
+
|
21
|
+
def some_content_present?
|
22
|
+
errors.add(:content, :blank) if file.blank? && content.blank?
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreatePlokLogs < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
return if table_exists?(:logs)
|
4
|
+
|
5
|
+
create_table :logs do |t|
|
6
|
+
t.string :category
|
7
|
+
t.string :loggable_type
|
8
|
+
t.integer :loggable_id
|
9
|
+
t.string :file
|
10
|
+
t.text :content
|
11
|
+
t.text :data
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/plok/engine.rb
CHANGED
@@ -1,4 +1,46 @@
|
|
1
|
+
# Can't use Plok::Engine.root yet at this point.
|
2
|
+
engine_root = File.expand_path('../..', __dir__)
|
3
|
+
Dir.glob("#{engine_root}/app/models/**/*.rb").each { |file| require file }
|
4
|
+
|
1
5
|
module Plok
|
2
6
|
class Engine < ::Rails::Engine
|
7
|
+
# https://hocnest.com/blog/testing-an-engine-with-rspec/
|
8
|
+
# https://edgeguides.rubyonrails.org/engines.html#critical-files
|
9
|
+
# This makes it so generators, helpers,... always reside in the engine's
|
10
|
+
# namespace. So when a model gets generated, it gets put into
|
11
|
+
# app/models/plok/log.rb.
|
12
|
+
#
|
13
|
+
# As you can see this is off for now, but if you do want it turned on
|
14
|
+
# you can always do "Log = Plok::Log" in an initializer file to ease the
|
15
|
+
# transition.
|
16
|
+
#isolate_namespace Plok
|
17
|
+
|
18
|
+
config.generators do |g|
|
19
|
+
g.test_framework :rspec
|
20
|
+
end
|
21
|
+
|
22
|
+
def class_exists?(class_name)
|
23
|
+
klass = Module.const_get(class_name.to_s)
|
24
|
+
klass.is_a?(Class)
|
25
|
+
rescue NameError
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
def module_exists?(module_name)
|
30
|
+
# By casting to a string and making a constant, we can assume module_name
|
31
|
+
# can be either one without it being a problem.
|
32
|
+
module_name.to_s.constantize.is_a?(Module)
|
33
|
+
rescue NameError
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
# You can call this in your spec/rails_helper.rb file so you can make use
|
38
|
+
# of the spec supports to test concerns.
|
39
|
+
#
|
40
|
+
# You cannot call it in the engine itself, because RSpec won't have the same
|
41
|
+
# context available when tests are ran.
|
42
|
+
def load_spec_supports
|
43
|
+
Dir.glob("#{root}/spec/{factories,support}/**/*.rb").each { |f| require f }
|
44
|
+
end
|
3
45
|
end
|
4
46
|
end
|
data/lib/plok/version.rb
CHANGED
data/lib/plok.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davy Hellemans
|
8
8
|
- Dave Lens
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-10-
|
12
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -39,6 +39,34 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: factory_bot_rails
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '6.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '6.0'
|
42
70
|
description: Some basics used for setting up rails projects
|
43
71
|
email:
|
44
72
|
- davy@blimp.be
|
@@ -52,8 +80,10 @@ files:
|
|
52
80
|
- app/assets/config/plok_manifest.js
|
53
81
|
- app/controllers/catch_all_controller.rb
|
54
82
|
- app/controllers/plok/version_controller.rb
|
55
|
-
-
|
83
|
+
- app/models/concerns/plok/loggable.rb
|
84
|
+
- app/models/log.rb
|
56
85
|
- config/routes.rb
|
86
|
+
- db/migrate/20211008130809_create_plok_logs.rb
|
57
87
|
- lib/plok.rb
|
58
88
|
- lib/plok/engine.rb
|
59
89
|
- lib/plok/version.rb
|
@@ -63,7 +93,7 @@ licenses:
|
|
63
93
|
- MIT
|
64
94
|
metadata:
|
65
95
|
allowed_push_host: https://rubygems.org
|
66
|
-
post_install_message:
|
96
|
+
post_install_message:
|
67
97
|
rdoc_options: []
|
68
98
|
require_paths:
|
69
99
|
- lib
|
@@ -78,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
108
|
- !ruby/object:Gem::Version
|
79
109
|
version: '0'
|
80
110
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
111
|
+
rubygems_version: 3.1.4
|
112
|
+
signing_key:
|
83
113
|
specification_version: 4
|
84
114
|
summary: CMS basics
|
85
115
|
test_files: []
|