litera 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43ce216fa357aed945907939fea46e685daa7d6408f96a97921cf23e1aec769e
4
+ data.tar.gz: 21bd3b5811723594dd6305c492722c8c119ea7e7f39493eac631b7934224ab60
5
+ SHA512:
6
+ metadata.gz: 6bfae89f0ac76b687b3ab7af8eb99355d1ba6ecb9b6b659cc459d3373bd3cb4716362287d38f2149391f30557322f6b975c9de007a476ac5ffe3a20099171746
7
+ data.tar.gz: f98eb603ef6522e0499da967c7cfe93e67365255c8ee0e8a8cedf667d21e41702b96502f22f2dfaf2d26b035c4ef2e26bca1c0206b4df018ae149f9d79f2db73
data/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # Litera - Messages Dashboard
2
+
3
+ This rails engine aims to provide a simple dasboard for the messages
4
+ received in your application regardless the services you are using to
5
+ handle your messages (GooglePubSub, Amazon SQS, Apache Kafka, etc) in
6
+ order to easily track and debug the data in your received data.
7
+
8
+ ## Installation
9
+
10
+ Add `Litera` to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "litera"
14
+ ```
15
+
16
+ And then install litera:
17
+
18
+ ```bash
19
+ rails g litera:install
20
+ ```
21
+
22
+ Install litera migrations:
23
+
24
+ ```bash
25
+ rails g litera:install:migrations
26
+ ```
27
+
28
+ Run pending migrations:
29
+
30
+ ```bash
31
+ rails db:migrate
32
+ ```
33
+
34
+ Add the following line to your `app/assets/config/manifest.js`:
35
+
36
+ ```javascript
37
+ //= link litera/application.css
38
+ ```
39
+
40
+ Lastly, mount litera engine in your `config/routes.rb`:
41
+
42
+ ```bash
43
+ Rails.application.routes.draw do
44
+ mount Litera::Engine => "/litera"
45
+ ...
46
+ end
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ Configure what is the name of the method that returns your current user
52
+ and how he will be authorized to access the messages dashboard.
53
+
54
+ ```ruby
55
+ Litera.setup do |config|
56
+ # Configure what is the name of the method that returns the current
57
+ # logged in user in your application.
58
+ # config.litera_user = :current_user
59
+
60
+ # Setup the name of the main application controller in your application.
61
+ # config.parent_controller = "ApplicationController"
62
+
63
+ # Define how the current user will be authorized ot not to access the
64
+ # messages dashboard.
65
+ # config.authorization = -> (user) do
66
+ # user.admin?
67
+ # end
68
+ end
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ Track your messages inmmediately after you received them using:
74
+
75
+ ```ruby
76
+ Litera::Message.create!({
77
+ service: :google_pub_sub,
78
+ body: message.body,
79
+ metadata: message.attributes,
80
+ external_id: message.message_id,
81
+ published_at: message.published_at
82
+ })
83
+ ```
84
+
85
+ You can use an active job if you want to save it in background:
86
+
87
+ ```ruby
88
+ Litera::MessageJob.perform_later({
89
+ service: :google_pub_sub,
90
+ body: message.body,
91
+ metadata: message.attributes,
92
+ external_id: message.message_id,
93
+ published_at: message.published_at
94
+ })
95
+ ```
96
+
97
+ ## Development
98
+
99
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
100
+ run `rake spec` to run the tests. You can also run `bin/console` for an
101
+ interactive prompt that will allow you to experiment.
102
+
103
+ To install this gem onto your local machine, run `bundle exec rake install`.
104
+ To release a new version, update the version number in `version.rb`, and
105
+ then run `bundle exec rake release`, which will create a git tag for the
106
+ version, push git commits and the created tag, and push the `.gem` file
107
+ to [rubygems.org](https://rubygems.org).
108
+
109
+ ## Contributing
110
+
111
+ Bug reports and pull requests are welcome on GitHub at https://github.com/amco/litera-rb.
112
+ This project is intended to be a safe, welcoming space for collaboration, and
113
+ contributors are expected to adhere to the
114
+ [code of conduct](https://github.com/amco/litera-rb/blob/master/CODE_OF_CONDUCT.md).
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the
119
+ [MIT License](https://opensource.org/licenses/MIT).
120
+
121
+ ## Code of Conduct
122
+
123
+ Everyone interacting in the Litera project's codebases, issue trackers, chat rooms
124
+ and mailing lists is expected to follow the
125
+ [code of conduct](https://github.com/amco/litera-rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+
5
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
6
+ load "rails/tasks/engine.rake"
7
+
8
+ load "rails/tasks/statistics.rake"
9
+
10
+ require "bundler/gem_tasks"
11
+ require "rspec/core/rake_task"
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
14
+
15
+ require "rubocop/rake_task"
16
+
17
+ RuboCop::RakeTask.new
18
+
19
+ task default: %i[spec rubocop]
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/litera .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,14 @@
1
+ .litera table, th, td {
2
+ border: 1px solid black;
3
+ border-collapse: collapse;
4
+ }
5
+
6
+ .litera table th {
7
+ text-align: left;
8
+ font-weight: bold;
9
+ text-transform: uppercase;
10
+ }
11
+
12
+ .litera table th, td {
13
+ padding: 5px;
14
+ }
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ class ApplicationController < Litera.parent_controller.constantize
5
+ before_action :authorize_litera_user
6
+
7
+ private
8
+
9
+ def litera_user
10
+ send(Litera.litera_user)
11
+ end
12
+
13
+ def authorize_litera_user
14
+ if !Litera.authorization.call(litera_user)
15
+ raise Litera::Errors::NotAuthorized
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Litera
2
+ class MessagesController < ApplicationController
3
+ include Pagy::Backend
4
+
5
+ def index
6
+ @pagy, @messages = pagy(Message.ordered)
7
+ end
8
+
9
+ def show
10
+ @message = Message.find(params[:id])
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ module ApplicationHelper
5
+ include Pagy::Frontend
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ class ApplicationJob < ActiveJob::Base
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ class MessageJob < ApplicationJob
5
+ def perform(data = {})
6
+ Litera::Message.create!(data)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Litera
2
+ class Message < ApplicationRecord
3
+ validates :body, presence: true
4
+ validates :service, presence: true
5
+ validates :metadata, presence: true
6
+ validates :external_id, presence: true
7
+ validates :published_at, presence: true
8
+
9
+ scope :ordered, -> { order(published_at: :desc) }
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Litera</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <%= stylesheet_link_tag "litera/application", media: "all" %>
8
+ </head>
9
+
10
+ <body class="litera">
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,27 @@
1
+ <h1><%= Litera::Message.model_name.human(count: 2) %></h1>
2
+
3
+ <table width="100%">
4
+ <thead>
5
+ <tr>
6
+ <th><%= Litera::Message.human_attribute_name(:published_at) %></th>
7
+ <th><%= Litera::Message.human_attribute_name(:service) %></th>
8
+ <th><%= Litera::Message.human_attribute_name(:id) %></th>
9
+ <th><%= Litera::Message.human_attribute_name(:metadata) %></th>
10
+ <th></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @messages.each do |message| %>
16
+ <tr>
17
+ <td><%= l(message.published_at) %></td>
18
+ <td><%= message.service %></td>
19
+ <td><%= message.external_id %></td>
20
+ <td><%= message.metadata.to_s.truncate(50).html_safe %></td>
21
+ <td><%= link_to t(".show"), message %></td>
22
+ </tr>
23
+ <% end %>
24
+ </body>
25
+ </table>
26
+
27
+ <%== pagy_nav(@pagy) %>
@@ -0,0 +1,32 @@
1
+ <h1>Message: <%= @message.external_id %></h1>
2
+
3
+ <table>
4
+ <tbody>
5
+ <tr>
6
+ <th><%= Litera::Message.human_attribute_name(:published_at) %></th>
7
+ <td><%= l(@message.published_at) %></td>
8
+ </tr>
9
+
10
+ <tr>
11
+ <th><%= Litera::Message.human_attribute_name(:service) %></th>
12
+ <td><%= @message.service %></td>
13
+ </tr>
14
+
15
+ <tr>
16
+ <th><%= Litera::Message.human_attribute_name(:id) %></th>
17
+ <td><%= @message.external_id %></td>
18
+ </tr>
19
+
20
+ <tr>
21
+ <th><%= Litera::Message.human_attribute_name(:metadata) %></th>
22
+ <td><pre><%= JSON.pretty_generate(@message.metadata) %></pre></td>
23
+ </tr>
24
+
25
+ <tr>
26
+ <th><%= Litera::Message.human_attribute_name(:body) %></th>
27
+ <td><pre><%= JSON.pretty_generate(@message.body) %></pre></td>
28
+ </tr>
29
+ </body>
30
+ </table>
31
+
32
+ <%= link_to t(".back"), messages_path %>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Litera::Engine.routes.draw do
2
+ resources :messages, only: %i[index show]
3
+ end
@@ -0,0 +1,15 @@
1
+ class CreateLiteraMessages < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :litera_messages do |t|
4
+ t.jsonb :body, default: {}
5
+ t.jsonb :metadata, default: {}
6
+ t.string :service
7
+ t.string :external_id
8
+ t.datetime :published_at
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :litera_messages, :published_at
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+ desc "Creates litera initializer."
8
+
9
+ def create_initializer
10
+ template "litera.rb", "config/initializers/litera.rb"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ Litera.setup do |config|
4
+ # Configure what is the name of the method that returns the current
5
+ # logged in user in your application.
6
+ # config.litera_user = :current_user
7
+
8
+ # Setup the name of the main application controller in your application.
9
+ # config.parent_controller = "ApplicationController"
10
+
11
+ # Define how the current user will be authorized ot not to access the
12
+ # messages dashboard.
13
+ # config.authorization = -> (user) do
14
+ # user.admin?
15
+ # end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ module Configuration
5
+ mattr_accessor :litera_user, default: :current_user
6
+ mattr_accessor :parent_controller, default: "ApplicationController"
7
+ mattr_accessor :authorization, default: -> (user) { user.admin? }
8
+
9
+ def setup
10
+ yield(self) if block_given?
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Litera
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec
9
+ g.fixture_replacement :factory_bot
10
+ g.factory_bot dir: "spec/factories"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ module Errors
5
+ class NotAuthorized < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Litera
4
+ VERSION = "0.1.0"
5
+ end
data/lib/litera.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "litera/version"
4
+ require "litera/engine"
5
+ require "litera/configuration"
6
+ require "litera/errors/not_authorized"
7
+
8
+ module Litera
9
+ extend Configuration
10
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :litera do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: litera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alejandro Gutiérrez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pagy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ description: Rails engine that provides a simple dashboard to track received messages
42
+ in your application.
43
+ email:
44
+ - alejandrodevs@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/config/litera_manifest.js
52
+ - app/assets/stylesheets/litera/application.css
53
+ - app/assets/stylesheets/litera/main.css
54
+ - app/controllers/litera/application_controller.rb
55
+ - app/controllers/litera/messages_controller.rb
56
+ - app/helpers/litera/application_helper.rb
57
+ - app/jobs/litera/application_job.rb
58
+ - app/jobs/litera/message_job.rb
59
+ - app/models/litera/application_record.rb
60
+ - app/models/litera/message.rb
61
+ - app/views/layouts/litera/application.html.erb
62
+ - app/views/litera/messages/index.html.erb
63
+ - app/views/litera/messages/show.html.erb
64
+ - config/routes.rb
65
+ - db/migrate/20221102211322_create_litera_messages.rb
66
+ - lib/generators/litera/install_generator.rb
67
+ - lib/generators/litera/templates/litera.rb
68
+ - lib/litera.rb
69
+ - lib/litera/configuration.rb
70
+ - lib/litera/engine.rb
71
+ - lib/litera/errors/not_authorized.rb
72
+ - lib/litera/version.rb
73
+ - lib/tasks/litera_tasks.rake
74
+ homepage: https://github.com/amco/litera-rb
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://github.com/amco/litera-rb
79
+ source_code_uri: https://github.com/amco/litera-rb
80
+ changelog_uri: https://github.com/amco/litera-rb/blob/master/CHANGELOG.md
81
+ rubygems_mfa_required: 'true'
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.7.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.3.7
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Rails engine dashboard for message tracking.
101
+ test_files: []