po_box 0.1.0 → 0.1.2

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: 4a96717f6fc9f8aee68cbf574b60c2da573d7693a1173279a84b16e1a1666d38
4
- data.tar.gz: b5b7dcb9dcea500041f806517edc8ece9cdc18af18241900ce28adc43dd525de
3
+ metadata.gz: cf5765334ed345c096a6e2432f6775772afc81d3830e9d668e3df23fb782a45f
4
+ data.tar.gz: bb13be4eaf786de61adf885bb0b3bc0df69c6740f3a94b5067512465c73d656c
5
5
  SHA512:
6
- metadata.gz: 5522631b60e572e57049274c7c730d257c44eb94d0ef900b528c628329dfd0ac68e0ea166be00c8773ae3c9d3c46693c6336971881205553228760259a637b9e
7
- data.tar.gz: d6209dc03e50daa7ff937fee1ae5b39075a4a54b7215a7e80ec9290b9502864f5e1fc341e0a3585eacdfa7d9baa7de34ee8c644032a4627c337ff649ed96fede
6
+ metadata.gz: 688da89cf7a2dc81c270580a85ebf838aeb9209c14644ccb297dd90faa81743a3631981b43f057a3637e484bb6ea88d1f3b5f19baa249fc3823c8436410854d1
7
+ data.tar.gz: 9c82e7fdbd57649e2f2e0cdd93d56ffa3532216dcc2bd9df123d3c8f79e5340acfed35acb0c606b3b86cf9dbc7365e9d7c807e774f3ab34328db6a6087d4f181
data/README.md CHANGED
@@ -4,8 +4,8 @@ PoBox is a Ruby on Rails engine that provides inboxes and email addresses for yo
4
4
 
5
5
  ## Requirements
6
6
 
7
- 1. [ActiveStorage](https://edgeguides.rubyonrails.org/active_storage_overview.html) needs to be installed and configured.
8
- 2. [ActionMailbox](https://edgeguides.rubyonrails.org/action_mailbox_basics.html) needs to be installed and configured.
7
+ 1. [ActiveStorage](https://edgeguides.rubyonrails.org/active_storage_overview.html) needs to be configured.
8
+ 2. [ActionMailbox](https://edgeguides.rubyonrails.org/action_mailbox_basics.html) needs to be configured.
9
9
  3. A model that the inbox and emails will be associated with needs to exist in the host application. e.g. `User` or `Account`.
10
10
 
11
11
  ## Installation
@@ -33,7 +33,7 @@ $ gem install po_box
33
33
  **IMPORTANT:** Make sure you have ActiveStorage and ActionMailbox installed and configured.
34
34
 
35
35
  1. `bin/rails po_box:install:migrations`
36
- 2. `bin/rails g po_box emailable_model` (where `emailable_model` is the name of the model you want to make emailable, e.g. `user`)
36
+ 2. `bin/rails g po_box emailable_model` (where `emailable_model` is the name of the model in your application you want to associate inboxes and email addresses to, e.g. `user`)
37
37
  3. `bin/rails db:migrate`
38
38
  4. `bin/rails po_box:backfill_emailables`
39
39
 
@@ -50,7 +50,7 @@ Send the email to the address that is associated with the emailable model. e.g.
50
50
  ```ruby
51
51
  User.inboxes.first.address
52
52
 
53
- # => "some#64b0@yourapp"
53
+ # => "some#64b0@yourapp.com"
54
54
  ```
55
55
 
56
56
  <!-- If your emailable_class is a User -->
@@ -42,13 +42,13 @@ module PoBox
42
42
  private
43
43
 
44
44
  def inbox_params
45
- params.require(:inbox).permit(:name, :address)
45
+ params.require(:inbox).permit(:emailable_type, :emailable_id, :address)
46
46
  end
47
47
 
48
48
  def set_inbox
49
49
  @inbox = Inbox.find(params[:id])
50
50
  rescue ActiveRecord::RecordNotFound
51
- redirect_to po_box_inboxes_path, notice: "Inbox not found"
51
+ redirect_to inboxes_path, notice: "Inbox not found"
52
52
  end
53
53
  end
54
54
  end
@@ -5,13 +5,13 @@ module PoBox
5
5
  included do
6
6
  has_many :inboxes, as: :emailable, class_name: "PoBox::Inbox", dependent: :destroy
7
7
 
8
- after_create_commit :set_inbox
8
+ after_create_commit :generate_inbox
9
9
 
10
10
  accepts_nested_attributes_for :inboxes, allow_destroy: true
11
11
 
12
12
  private
13
13
 
14
- def set_inbox
14
+ def generate_inbox
15
15
  return if inboxes.any?
16
16
 
17
17
  inbox_address = if email.present?
@@ -23,7 +23,7 @@ module PoBox
23
23
  inbox = inboxes.new
24
24
  loop do
25
25
  inbox.address = inbox_address
26
- break unless PoBox.emailable_class.joins(:inboxes).where(po_box_inboxes: {address: inbox.address}).exists?
26
+ break unless PoBox::Inbox.find_by(address: inbox.address).present?
27
27
  end
28
28
 
29
29
  save
@@ -1,5 +1,18 @@
1
1
  module PoBox
2
- class ApplicationRecord < ActiveRecord::Base
2
+ class ApplicationRecord < ::ActiveRecord::Base
3
3
  self.abstract_class = true
4
+
5
+ def self.sort_by_params(column, direction)
6
+ sortable_column = column.presence_in(sortable_columns) || "created_at"
7
+ order(sortable_column => direction)
8
+ end
9
+
10
+ # Returns an array of sortable columns on the model
11
+ # Used with the Sortable controller concern
12
+ #
13
+ # Override this method to add/remove sortable columns
14
+ def self.sortable_columns
15
+ @sortable_columns ||= columns.map(&:name)
16
+ end
4
17
  end
5
18
  end
@@ -7,5 +7,7 @@ module PoBox
7
7
  validates :from, presence: true
8
8
 
9
9
  delegate :raw_source, to: :body
10
+
11
+ scope :for_emailable, ->(emailable) { joins(:inbox).where(po_box_inboxes: {emailable: emailable}) }
10
12
  end
11
13
  end
@@ -2,6 +2,8 @@ module PoBox
2
2
  class Inbox < ApplicationRecord
3
3
  belongs_to :emailable, polymorphic: true, class_name: PoBox.emailable_class.to_s
4
4
 
5
+ validates :address, presence: true, uniqueness: true
6
+
5
7
  has_many :emails, class_name: "PoBox::Email", dependent: :destroy
6
8
 
7
9
  define_method PoBox.emailable_class.to_s.underscore do
@@ -9,6 +9,11 @@
9
9
  </ul>
10
10
  </div>
11
11
  <% end %>
12
+ <div>
13
+ <%= form.label "Emailable ID", style: "display: block" %>
14
+ <%= form.number_field :emailable_id %>
15
+ <%= form.hidden_field :emailable_type, value: PoBox.emailable_class %>
16
+ </div>
12
17
  <div>
13
18
  <%= form.label :address, style: "display: block" %>
14
19
  <%= form.text_field :address %>
@@ -1,3 +1,3 @@
1
1
  module PoBox
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: po_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Policastro