plok 0.2.2 → 0.2.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: 79336cf5991e14af6e352e3d80b16f8acdd84351a55b746e16a50281e93fc74d
4
- data.tar.gz: 27e9ce0535aa34efe754ef698110e9d4178e1f7f63420cc89e625c7ba6967416
3
+ metadata.gz: 7c83d448013e7832bf4b624c51592b39f336a642b9edf197135792ac4418a63e
4
+ data.tar.gz: c7ea5c310c9f68f4005b04750bc1bc93696846ec0f8c6b4ec7147c298d978af7
5
5
  SHA512:
6
- metadata.gz: e82b8263bcd29fbaf48dad8dc30f45d458c46d8cdf3bad552c5bc568dec7678090645c06c9bf03d0fb25aa437556b610ff957b3e3ef57a26266fdb5ceb5a12a8
7
- data.tar.gz: de6a608365e8b62cad80cbc6435ecb3f76f9569fb8df2d67255701a559c54bc99a9a59c8c5ec83aab4cdc11e6d704b4b82b3901a52c9b8d73f36ad881abb99c4
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
@@ -1,3 +1,3 @@
1
1
  module Plok
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
data/lib/plok.rb CHANGED
@@ -1,6 +1,5 @@
1
- require "plok/version"
2
- require "plok/engine"
1
+ require 'plok/version'
2
+ require 'plok/engine'
3
3
 
4
4
  module Plok
5
- # Your code goes here...
6
5
  end
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.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-04 00:00:00.000000000 Z
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
- - config/plok.yml
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.2.28
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: []
data/config/plok.yml DELETED
@@ -1,9 +0,0 @@
1
- development:
2
- modules:
3
- - flexible_content
4
- - snippets
5
- - settings
6
- - queued_tasks
7
- - email_templates
8
- - pages
9
- - redirects