draft_box 0.0.2 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 810d24fb1ae9b877a1de545a4b91ae5a8e501f2817d823ba799afbb609b9c861
4
- data.tar.gz: 8d347ecc7d1662422f7ea02ec74afca947a82c77738e4214ef5c124306f654d0
3
+ metadata.gz: df1480e5f5f34ba3e74ca9d1da1126ffe5de868a99c1e85dbfc50ef78489446f
4
+ data.tar.gz: 566c5480ab8a6367deee4090e30e908b9abe0b6116290e77469c17315874be67
5
5
  SHA512:
6
- metadata.gz: cdc8bedba1bcd7818f959db5cd49a7008fcbfc8488e9ffa1609e5a1f7bc36f4f9b4e56bf0b1531b0b3a854944b8fae90e7ecca3da26299195fb1e0c010a70657
7
- data.tar.gz: e659f0b821bd207e1e8f11865cbef280a8fa5d6d7386bb8a5002acb641d08ea6710b122215a8922aa825905680a04a80df20985aae3270f1397edbddde8edf70
6
+ metadata.gz: ba24288561491471a5baf1d346a5033c50515479b08a496195c9eaaf40245ca318268f0854200e406a3943af06438b16c970d8dea2ea794757de1fd1e1344536
7
+ data.tar.gz: caf7c0b06cdc1a2dfdfa6adac128981b27b54954cbeebbc6f5715ec1f65528ac9393acacbd44545b7d8db56d98e698dbc6ff36f2d83a9496f70b082812494b44
@@ -0,0 +1,5 @@
1
+ module DraftBox
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception, unless: -> { Rails.configuration.try(:api_only) }
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module DraftBox
2
+ class AttachmentsController < ApplicationController
3
+ def show
4
+ @email = DraftBox::Email.find(params[:email_id])
5
+ @attachment = @email.attachments.find(params[:id])
6
+
7
+ send_data @attachment.data, filename: @attachment.filename, type: @attachment.content_type
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ unless Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled?
2
+ require_dependency 'draft_box/application_controller'
3
+ end
4
+
5
+ module DraftBox
6
+ class EmailsController < ApplicationController
7
+ before_action :set_emails, only: [:index, :show]
8
+
9
+ def index; end
10
+
11
+ def show
12
+ @email = DraftBox::Email.find(params[:id])
13
+ end
14
+
15
+ def destroy
16
+ DraftBox::Email.find(params[:id]).destroy!
17
+ redirect_to draft_box.emails_path
18
+ end
19
+
20
+ def destroy_all
21
+ DraftBox::Email.destroy_all
22
+ redirect_to draft_box.emails_path
23
+ end
24
+
25
+ private
26
+
27
+ def set_emails
28
+ @emails = DraftBox::Email.includes(:attachments).order(created_at: :desc)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module DraftBox
2
+ class Attachment < ApplicationRecord
3
+ self.table_name = 'draft_box_attachments'
4
+
5
+ belongs_to :email, class_name: 'DraftBox::Email', foreign_key: :draft_box_email_id
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ module DraftBox
2
+ class Email < ApplicationRecord
3
+ self.table_name = 'draft_box_emails'
4
+
5
+ has_many :attachments, class_name: 'DraftBox::Attachment', dependent: :destroy, foreign_key: :draft_box_email_id
6
+
7
+ if connection.class.to_s.match?(/mysql/i)
8
+ serialize :recipients, coder: JSON
9
+ serialize :carbon_copies, coder: JSON
10
+ serialize :blind_copies, coder: JSON
11
+ end
12
+ end
13
+ end
14
+
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ DraftBox::Engine.routes.draw do
2
+ get '/', to: 'emails#index', as: :emails
3
+ get '/:id', to: 'emails#show', as: :email
4
+ delete '/', to: 'emails#destroy_all', as: :destroy_all
5
+ delete '/:id', to: 'emails#destroy', as: :destroy
6
+ get '/:email_id/attachments/:id', to: 'attachments#show', as: :attachment
7
+ end
@@ -3,7 +3,7 @@ module DraftBox
3
3
  module_function
4
4
 
5
5
  def to_s
6
- '0.0.2'
6
+ '0.0.4'
7
7
  end
8
8
  end
9
9
  end
@@ -30,7 +30,15 @@ module Generators
30
30
  end
31
31
 
32
32
  def sqlite?
33
- ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").adapter_class.to_s.match?(/sqlite/i)
33
+ db_adapter.match?(/sqlite/i)
34
+ end
35
+
36
+ def mysql?
37
+ db_adapter.match?(/mysql/i)
38
+ end
39
+
40
+ def db_adapter
41
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").adapter_class.to_s
34
42
  end
35
43
  end
36
44
  end
@@ -4,17 +4,21 @@ class CreateDraftBoxEmails < ActiveRecord::Migration<%= migration_version %>
4
4
  t.string :subject
5
5
  t.text :body
6
6
  t.string :from
7
- <% unless sqlite? -%>
8
- t.string :recipients, array: true, default: []
9
- t.string :carbon_copies, array: true, default: []
10
- t.string :blind_copies, array: true, default: []
11
- <% else %>
7
+ <% if mysql? -%>
8
+ t.string :recipients, default: '[]'
9
+ t.string :carbon_copies, default: '[]'
10
+ t.string :blind_copies, default: '[]'
11
+ <% elsif sqlite? %>
12
12
  t.json :recipients, null: false, default: []
13
13
  t.json :carbon_copies, null: false, default: []
14
14
  t.json :blind_copies, null: false, default: []
15
15
  t.check_constraint "JSON_TYPE(recipients) = 'array'", name: 'draft_box_emails_recipients_is_array'
16
16
  t.check_constraint "JSON_TYPE(carbon_copies) = 'array'", name: 'draft_box_emails_carbon_copies_is_array'
17
17
  t.check_constraint "JSON_TYPE(blind_copies) = 'array'", name: 'draft_box_emails_blind_copies_is_array'
18
+ <% else %>
19
+ t.string :recipients, array: true, default: []
20
+ t.string :carbon_copies, array: true, default: []
21
+ t.string :blind_copies, array: true, default: []
18
22
  <% end -%>
19
23
 
20
24
  t.timestamps
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draft_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Dąbrowski
@@ -17,6 +17,12 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - app/controllers/draft_box/application_controller.rb
21
+ - app/controllers/draft_box/attachments_controller.rb
22
+ - app/controllers/draft_box/emails_controller.rb
23
+ - app/models/draft_box/attachment.rb
24
+ - app/models/draft_box/email.rb
25
+ - config/routes.rb
20
26
  - lib/draft_box.rb
21
27
  - lib/draft_box/delivery_method.rb
22
28
  - lib/draft_box/engine.rb
@@ -24,7 +30,7 @@ files:
24
30
  - lib/generators/draft_box/install_generator.rb
25
31
  - lib/generators/draft_box/templates/attachments_migration.rb
26
32
  - lib/generators/draft_box/templates/emails_migration.rb
27
- homepage:
33
+ homepage: https://github.com/paweldabrowski/draft_box
28
34
  licenses: []
29
35
  metadata: {}
30
36
  post_install_message:
@@ -42,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
48
  - !ruby/object:Gem::Version
43
49
  version: '0'
44
50
  requirements: []
45
- rubygems_version: 3.4.10
51
+ rubygems_version: 3.2.32
46
52
  signing_key:
47
53
  specification_version: 4
48
54
  summary: A web interface for browsing Ruby on Rails sent emails with support for distributed