cells-mailer 0.2.0 → 0.3.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 +4 -4
 - data/CHANGELOG.md +4 -0
 - data/README.md +43 -8
 - data/lib/cell/mailer/version.rb +1 -1
 - data/lib/cell/mailer.rb +45 -2
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b2a9a4b39ab44d4d9ec2e0a5768d9dbc5c860343
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4b4f28cb58ac9ad421f92d18c8bf28fcc891319c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f903b79ac439061cac98c370322482015c891cf59d6126679eb95a3213c67ef35532f3dd13b24054077bb8e56d384263f6348e1812f03fbb52b0b4855daa8868
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: aa48d673a02daf1df42b0ec2d803485adb1d86138c7b45fa72b15c973e66f414be9b49c5ef47574d224e9ab0390cf298dc2c25c28d379184107a36747391e83b
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,5 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Changelog
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            ## v0.3.0 [☰](https://github.com/timoschilling/cells-mailer/compare/v0.2.0...v0.3.0)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            * class level options
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       3 
7 
     | 
    
         
             
            ## v0.2.0 [☰](https://github.com/timoschilling/cells-mailer/compare/v0.1.0...v0.2.0)
         
     | 
| 
       4 
8 
     | 
    
         | 
| 
       5 
9 
     | 
    
         
             
            * Allow instance methods for `subject`, `from` and `to`
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Cells::Mailer
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            Provides mail functionality for [Cells](https://github.com/apotonick/cells/).
         
     | 
| 
      
 3 
     | 
    
         
            +
            Provides mail functionality for [Cells](https://github.com/apotonick/cells/) via the [Mail](https://github.com/mikel/mail) gem.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            ## Installation
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
         @@ -16,8 +16,9 @@ And then execute: 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            ## Configuration
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            Cells::Mailer don't provide  
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
            Cells::Mailer don't provide a global delivery configuration at the moment. 
         
     | 
| 
      
 20 
     | 
    
         
            +
            You can configure the `deliver_method` of `Mail` per [class level](#class-level-configurations) or take a look 
         
     | 
| 
      
 21 
     | 
    
         
            +
            at the [mail](https://github.com/mikel/mail) gem for any other configuration options.
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
            ## Usage
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
         @@ -57,10 +58,44 @@ I don't know why you should use it, but you can also pass in a body as argument. 
     | 
|
| 
       57 
58 
     | 
    
         
             
            UserNotificationCell.(user).deliver(..., body: "Hello user")
         
     | 
| 
       58 
59 
     | 
    
         
             
            ```
         
     | 
| 
       59 
60 
     | 
    
         | 
| 
      
 61 
     | 
    
         
            +
            ### Instance method arguments
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            You can use instance methods to receive the value for `to`, `from` and `subject`.
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 66 
     | 
    
         
            +
            class UserNotificationCell < Cell::ViewModel
         
     | 
| 
      
 67 
     | 
    
         
            +
              include Cell::Mailer
         
     | 
| 
      
 68 
     | 
    
         
            +
              property :user_name
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              def subject
         
     | 
| 
      
 71 
     | 
    
         
            +
                "Hello #{user_name}"
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
            end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            UserNotificationCell.(user).deliver(..., subject: :subject)
         
     | 
| 
      
 76 
     | 
    
         
            +
            ```
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            ### Class level configurations
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            You can use class level configurations for `to`, `from`, `subject` and `mail_options`.
         
     | 
| 
      
 81 
     | 
    
         
            +
            `mail_options` are passed to `Mail`, could be used to configure `Mail#delivery_method` per Cell class.
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 84 
     | 
    
         
            +
            class UserNotificationCell < Cell::ViewModel
         
     | 
| 
      
 85 
     | 
    
         
            +
              include Cell::Mailer
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
              mailer do
         
     | 
| 
      
 88 
     | 
    
         
            +
                from "nick@trailblazer.to"
         
     | 
| 
      
 89 
     | 
    
         
            +
                subject "nick loves good code!"
         
     | 
| 
      
 90 
     | 
    
         
            +
                mail_options delivery_method: :smtp
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
            end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            UserNotificationCell.(user).deliver(to: "timo@schilling.io")
         
     | 
| 
      
 95 
     | 
    
         
            +
            ```
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
            This configurations will be inherited.
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
       60 
99 
     | 
    
         
             
            ## Roadmap
         
     | 
| 
       61 
100 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
              - `from`
         
     | 
| 
       64 
     | 
    
         
            -
              - `to`
         
     | 
| 
       65 
     | 
    
         
            -
              - `subject`
         
     | 
| 
       66 
     | 
    
         
            -
            - Provide class level `mail` delivery configurations
         
     | 
| 
      
 101 
     | 
    
         
            +
            * making a real config object
         
     | 
    
        data/lib/cell/mailer/version.rb
    CHANGED
    
    
    
        data/lib/cell/mailer.rb
    CHANGED
    
    | 
         @@ -4,7 +4,11 @@ require "mail" 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            module Cell
         
     | 
| 
       6 
6 
     | 
    
         
             
              module Mailer
         
     | 
| 
       7 
     | 
    
         
            -
                def  
     | 
| 
      
 7 
     | 
    
         
            +
                def self.included(base)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  base.extend ClassMethods
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def deliver(options = {})
         
     | 
| 
       8 
12 
     | 
    
         
             
                  mail = Mail.new process_mail_options(options)
         
     | 
| 
       9 
13 
     | 
    
         
             
                  mail.deliver
         
     | 
| 
       10 
14 
     | 
    
         
             
                end
         
     | 
| 
         @@ -12,12 +16,51 @@ module Cell 
     | 
|
| 
       12 
16 
     | 
    
         
             
                private
         
     | 
| 
       13 
17 
     | 
    
         | 
| 
       14 
18 
     | 
    
         
             
                def process_mail_options(options)
         
     | 
| 
       15 
     | 
    
         
            -
                   
     | 
| 
      
 19 
     | 
    
         
            +
                  if options[:body] && options[:method]
         
     | 
| 
      
 20 
     | 
    
         
            +
                    raise ArgumentError, "You can't pass in `:method` and `:body` at once!"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       16 
23 
     | 
    
         
             
                  [:to, :subject, :from].each do |field|
         
     | 
| 
       17 
24 
     | 
    
         
             
                    options[field] = send(options[field]) if options[field].is_a? Symbol
         
     | 
| 
       18 
25 
     | 
    
         
             
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  [:to, :subject, :from].each do |field|
         
     | 
| 
      
 28 
     | 
    
         
            +
                    options[field] ||= self.class.send(field)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  (self.class.mail_options || {}).each do |key, value|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    options[key] = value
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  state = options.delete(:method) || :show
         
     | 
| 
       19 
36 
     | 
    
         
             
                  options[:body] ||= call(state)
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
       20 
38 
     | 
    
         
             
                  options
         
     | 
| 
       21 
39 
     | 
    
         
             
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                module ClassMethods
         
     | 
| 
      
 42 
     | 
    
         
            +
                  def self.extended(base)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    base.extend Uber::InheritableAttr
         
     | 
| 
      
 44 
     | 
    
         
            +
                    base.inheritable_attr :to
         
     | 
| 
      
 45 
     | 
    
         
            +
                    base.inheritable_attr :from
         
     | 
| 
      
 46 
     | 
    
         
            +
                    base.inheritable_attr :subject
         
     | 
| 
      
 47 
     | 
    
         
            +
                    base.inheritable_attr :mail_options
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  def mailer(&block)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    tap &block
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  def inheritable_attr(name, options={})
         
     | 
| 
      
 55 
     | 
    
         
            +
                    super
         
     | 
| 
      
 56 
     | 
    
         
            +
                    instance_eval %Q{
         
     | 
| 
      
 57 
     | 
    
         
            +
                      def #{name}(value = :__undefined)
         
     | 
| 
      
 58 
     | 
    
         
            +
                        return self.#{name} = value if value != :__undefined
         
     | 
| 
      
 59 
     | 
    
         
            +
                        return @#{name} if instance_variable_defined?(:@#{name})
         
     | 
| 
      
 60 
     | 
    
         
            +
                        @#{name} = Uber::InheritableAttribute.inherit_for(self, :#{name}, #{options})
         
     | 
| 
      
 61 
     | 
    
         
            +
                      end
         
     | 
| 
      
 62 
     | 
    
         
            +
                    }
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
       22 
65 
     | 
    
         
             
              end
         
     | 
| 
       23 
66 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: cells-mailer
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Timo Schilling
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-11- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-11-08 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: cells
         
     |