paperclip-atompub 0.0.1
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.
- data/MIT-LICENSE +20 -0
 - data/README.rdoc +44 -0
 - data/Rakefile +27 -0
 - data/app/assets/javascripts/paperclip-atompub/application.js +15 -0
 - data/app/assets/stylesheets/paperclip-atompub/application.css +13 -0
 - data/app/controllers/paperclip-atompub/application_controller.rb +4 -0
 - data/app/helpers/paperclip-atompub/application_helper.rb +4 -0
 - data/app/models/paperclip_atompub/attachment.rb +6 -0
 - data/app/views/layouts/paperclip-atompub/application.html.erb +14 -0
 - data/config/routes.rb +2 -0
 - data/db/migrate/20121108051952_create_paperclip_atompub_attachments.rb +16 -0
 - data/lib/paperclip/storage/atompub.rb +116 -0
 - data/lib/paperclip-atompub/engine.rb +5 -0
 - data/lib/paperclip-atompub/version.rb +3 -0
 - data/lib/paperclip-atompub.rb +7 -0
 - data/lib/tasks/paperclip-atompub_tasks.rake +4 -0
 - metadata +157 -0
 
    
        data/MIT-LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright 2012 YOURNAME
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 4 
     | 
    
         
            +
            a copy of this software and associated documentation files (the
         
     | 
| 
      
 5 
     | 
    
         
            +
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 6 
     | 
    
         
            +
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 7 
     | 
    
         
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 8 
     | 
    
         
            +
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 9 
     | 
    
         
            +
            the following conditions:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be
         
     | 
| 
      
 12 
     | 
    
         
            +
            included in all copies or substantial portions of the Software.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 15 
     | 
    
         
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 16 
     | 
    
         
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 17 
     | 
    
         
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 18 
     | 
    
         
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 19 
     | 
    
         
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 20 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.rdoc
    ADDED
    
    | 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            = Paperclip Atompub Storage
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            (Atompub Media Resource only.)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            == Installation
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              gem 'paperclip-atompub', '~> 0.0.1'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              bundle exec rake paperclip_atompub:install:migrations
         
     | 
| 
      
 10 
     | 
    
         
            +
              bundle exec rake db:migrate
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            == Usage
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            === Simple
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              class User < ActiveRecord::Base
         
     | 
| 
      
 17 
     | 
    
         
            +
                attr_accessible :name, :avatar
         
     | 
| 
      
 18 
     | 
    
         
            +
                has_attached_file :avatar,
         
     | 
| 
      
 19 
     | 
    
         
            +
                  :storage => :atompub,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :atompub_config => {
         
     | 
| 
      
 21 
     | 
    
         
            +
                    :service_uri => 'http://atompub.host/atomsvc',
         
     | 
| 
      
 22 
     | 
    
         
            +
                    :media_collection_uri => 'http://atompub.host/resources'
         
     | 
| 
      
 23 
     | 
    
         
            +
                  },
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :atompub_credentials => {
         
     | 
| 
      
 25 
     | 
    
         
            +
                    :username => 'USERNAME',
         
     | 
| 
      
 26 
     | 
    
         
            +
                    :password => 'PASSWORD'
         
     | 
| 
      
 27 
     | 
    
         
            +
                  },
         
     | 
| 
      
 28 
     | 
    
         
            +
                  :styles => { :medium => "300x300>", :thumb => "100x100>" }
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            === Dynamic Credentials
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              :atompub_credentials => lambda { |attachment|
         
     | 
| 
      
 34 
     | 
    
         
            +
                user = attachment.instance # => #<User id:1>
         
     | 
| 
      
 35 
     | 
    
         
            +
                { :username => user.atompub_username, :password => user.atompub_password }
         
     | 
| 
      
 36 
     | 
    
         
            +
              },
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            == Contributing to paperclip-atompub
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            Fork, fix, then send me a pull request.
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            == Copyright
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            Copyright(c) 2012 Yuichi Takeuchi, released under the MIT license
         
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env rake
         
     | 
| 
      
 2 
     | 
    
         
            +
            begin
         
     | 
| 
      
 3 
     | 
    
         
            +
              require 'bundler/setup'
         
     | 
| 
      
 4 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 5 
     | 
    
         
            +
              puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
         
     | 
| 
      
 6 
     | 
    
         
            +
            end
         
     | 
| 
      
 7 
     | 
    
         
            +
            begin
         
     | 
| 
      
 8 
     | 
    
         
            +
              require 'rdoc/task'
         
     | 
| 
      
 9 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 10 
     | 
    
         
            +
              require 'rdoc/rdoc'
         
     | 
| 
      
 11 
     | 
    
         
            +
              require 'rake/rdoctask'
         
     | 
| 
      
 12 
     | 
    
         
            +
              RDoc::Task = Rake::RDocTask
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            RDoc::Task.new(:rdoc) do |rdoc|
         
     | 
| 
      
 16 
     | 
    
         
            +
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
      
 17 
     | 
    
         
            +
              rdoc.title    = 'PaperclipAtompub'
         
     | 
| 
      
 18 
     | 
    
         
            +
              rdoc.options << '--line-numbers'
         
     | 
| 
      
 19 
     | 
    
         
            +
              rdoc.rdoc_files.include('README.rdoc')
         
     | 
| 
      
 20 
     | 
    
         
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            Bundler::GemHelper.install_tasks
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // This is a manifest file that'll be compiled into application.js, which will include all the files
         
     | 
| 
      
 2 
     | 
    
         
            +
            // listed below.
         
     | 
| 
      
 3 
     | 
    
         
            +
            //
         
     | 
| 
      
 4 
     | 
    
         
            +
            // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
         
     | 
| 
      
 5 
     | 
    
         
            +
            // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
         
     | 
| 
      
 6 
     | 
    
         
            +
            //
         
     | 
| 
      
 7 
     | 
    
         
            +
            // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
         
     | 
| 
      
 8 
     | 
    
         
            +
            // the compiled file.
         
     | 
| 
      
 9 
     | 
    
         
            +
            //
         
     | 
| 
      
 10 
     | 
    
         
            +
            // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
         
     | 
| 
      
 11 
     | 
    
         
            +
            // GO AFTER THE REQUIRES BELOW.
         
     | 
| 
      
 12 
     | 
    
         
            +
            //
         
     | 
| 
      
 13 
     | 
    
         
            +
            //= require jquery
         
     | 
| 
      
 14 
     | 
    
         
            +
            //= require jquery_ujs
         
     | 
| 
      
 15 
     | 
    
         
            +
            //= require_tree .
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 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 vendor/assets/stylesheets of plugins, if any, 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 top of the
         
     | 
| 
      
 9 
     | 
    
         
            +
             * compiled file, but it's generally better to create a new file per style scope.
         
     | 
| 
      
 10 
     | 
    
         
            +
             *
         
     | 
| 
      
 11 
     | 
    
         
            +
             *= require_self
         
     | 
| 
      
 12 
     | 
    
         
            +
             *= require_tree .
         
     | 
| 
      
 13 
     | 
    
         
            +
             */
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <!DOCTYPE html>
         
     | 
| 
      
 2 
     | 
    
         
            +
            <html>
         
     | 
| 
      
 3 
     | 
    
         
            +
            <head>
         
     | 
| 
      
 4 
     | 
    
         
            +
              <title>PaperclipAtompub</title>
         
     | 
| 
      
 5 
     | 
    
         
            +
              <%= stylesheet_link_tag    "paperclip-atompub/application", :media => "all" %>
         
     | 
| 
      
 6 
     | 
    
         
            +
              <%= javascript_include_tag "paperclip-atompub/application" %>
         
     | 
| 
      
 7 
     | 
    
         
            +
              <%= csrf_meta_tags %>
         
     | 
| 
      
 8 
     | 
    
         
            +
            </head>
         
     | 
| 
      
 9 
     | 
    
         
            +
            <body>
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            <%= yield %>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            </body>
         
     | 
| 
      
 14 
     | 
    
         
            +
            </html>
         
     | 
    
        data/config/routes.rb
    ADDED
    
    
| 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class CreatePaperclipAtompubAttachments < ActiveRecord::Migration
         
     | 
| 
      
 2 
     | 
    
         
            +
              def change
         
     | 
| 
      
 3 
     | 
    
         
            +
                create_table :paperclip_atompub_attachments do |t|
         
     | 
| 
      
 4 
     | 
    
         
            +
                  t.string :instance_type, :null => false
         
     | 
| 
      
 5 
     | 
    
         
            +
                  t.integer :instance_id, :null => false
         
     | 
| 
      
 6 
     | 
    
         
            +
                  t.string :attachment_name, :null => false
         
     | 
| 
      
 7 
     | 
    
         
            +
                  t.string :style, :null => false
         
     | 
| 
      
 8 
     | 
    
         
            +
                  t.string :resource_uri, :null => false
         
     | 
| 
      
 9 
     | 
    
         
            +
                  t.string :content_src, :null => false
         
     | 
| 
      
 10 
     | 
    
         
            +
                  t.timestamps
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
                add_index :paperclip_atompub_attachments, [:instance_type, :instance_id], :name => 'attachments_on_instance_type_and_instance_id'
         
     | 
| 
      
 13 
     | 
    
         
            +
                add_index :paperclip_atompub_attachments, [:instance_type, :instance_id, :attachment_name], :name => 'instance_type_and_instance_id_and_attachment_name'
         
     | 
| 
      
 14 
     | 
    
         
            +
                add_index :paperclip_atompub_attachments, [:instance_type, :instance_id, :attachment_name, :style], :unique => true, :name => 'instance_type_and_instance_id_and_attachment_name_and_style'
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,116 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'atomutil'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Paperclip
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Storage
         
     | 
| 
      
 5 
     | 
    
         
            +
                module Atompub
         
     | 
| 
      
 6 
     | 
    
         
            +
                  def self.extended(base)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    base.instance_eval do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      (@options.delete(:atompub_config) || {}).each do |key, value|
         
     | 
| 
      
 9 
     | 
    
         
            +
                        @options[:"atompub_#{key}"] = value
         
     | 
| 
      
 10 
     | 
    
         
            +
                      end
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  def path(style_name = default_style)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    style_name
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  def url(style_name = default_style)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    attachment = atompub_attachment(style_name)
         
     | 
| 
      
 20 
     | 
    
         
            +
                    attachment ? attachment.content_src : nil
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  def exists?(style_name = default_style)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    if original_filename
         
     | 
| 
      
 25 
     | 
    
         
            +
                      ! atompub_entry(style_name).nil?
         
     | 
| 
      
 26 
     | 
    
         
            +
                    else
         
     | 
| 
      
 27 
     | 
    
         
            +
                      false
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  
         
     | 
| 
      
 31 
     | 
    
         
            +
                  def flush_writes #:nodoc:
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @queued_for_write.each do |style, file|
         
     | 
| 
      
 33 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 34 
     | 
    
         
            +
                        log("saving #{path(style)}")
         
     | 
| 
      
 35 
     | 
    
         
            +
                        attachment = atompub_attachment(style)
         
     | 
| 
      
 36 
     | 
    
         
            +
                        attachment.resource_uri = atompub_client.create_media(options[:atompub_media_collection_uri], file.path, file.content_type)
         
     | 
| 
      
 37 
     | 
    
         
            +
                        attachment.content_src = atompub_client.get_entry(attachment.resource_uri).content.src
         
     | 
| 
      
 38 
     | 
    
         
            +
                        attachment.save!
         
     | 
| 
      
 39 
     | 
    
         
            +
                      ensure
         
     | 
| 
      
 40 
     | 
    
         
            +
                        file.rewind
         
     | 
| 
      
 41 
     | 
    
         
            +
                      end
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  def flush_deletes #:nodoc:
         
     | 
| 
      
 46 
     | 
    
         
            +
                    @queued_for_delete.each do |path|
         
     | 
| 
      
 47 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 48 
     | 
    
         
            +
                        log("deleting #{path}")
         
     | 
| 
      
 49 
     | 
    
         
            +
                        entry = atompub_entry(path)
         
     | 
| 
      
 50 
     | 
    
         
            +
                        attachment = atompub_attachment(path).destroy
         
     | 
| 
      
 51 
     | 
    
         
            +
                        attachment.destroy
         
     | 
| 
      
 52 
     | 
    
         
            +
                        atompub_client.delete_media(entry.edit_media_link)
         
     | 
| 
      
 53 
     | 
    
         
            +
                      rescue ::Atompub::RequestError
         
     | 
| 
      
 54 
     | 
    
         
            +
                        # Ignore this.
         
     | 
| 
      
 55 
     | 
    
         
            +
                      end
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
                    @queued_for_delete = []
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  private
         
     | 
| 
      
 61 
     | 
    
         
            +
                  def atompub_auth
         
     | 
| 
      
 62 
     | 
    
         
            +
                    @atompub_auth ||= ::Atompub::Auth::Wsse.new(atompub_credentials)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  def atompub_client
         
     | 
| 
      
 66 
     | 
    
         
            +
                    @atompub_client ||= begin
         
     | 
| 
      
 67 
     | 
    
         
            +
                                          client = ::Atompub::Client.new(:auth => atompub_auth)
         
     | 
| 
      
 68 
     | 
    
         
            +
                                          client.get_service(options[:atompub_service_uri])
         
     | 
| 
      
 69 
     | 
    
         
            +
                                          client
         
     | 
| 
      
 70 
     | 
    
         
            +
                                        end
         
     | 
| 
      
 71 
     | 
    
         
            +
                    
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  def atompub_credentials
         
     | 
| 
      
 75 
     | 
    
         
            +
                    @atompub_credentials ||= parse_credentials(options[:atompub_credentials]).with_indifferent_access
         
     | 
| 
      
 76 
     | 
    
         
            +
                  end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                  def parse_credentials(creds)
         
     | 
| 
      
 79 
     | 
    
         
            +
                    creds = creds.respond_to?('call') ? creds.call(self) : creds
         
     | 
| 
      
 80 
     | 
    
         
            +
                    creds = find_credentials(creds).stringify_keys
         
     | 
| 
      
 81 
     | 
    
         
            +
                    env = Object.const_defined?(:Rails) ? Rails.env : nil
         
     | 
| 
      
 82 
     | 
    
         
            +
                    (creds[env] || creds).symbolize_keys
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  def find_credentials(creds)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    case creds
         
     | 
| 
      
 87 
     | 
    
         
            +
                    when File
         
     | 
| 
      
 88 
     | 
    
         
            +
                      YAML::load(ERB.new(File.read(creds.path)).result)
         
     | 
| 
      
 89 
     | 
    
         
            +
                    when String, Pathname
         
     | 
| 
      
 90 
     | 
    
         
            +
                      YAML::load(ERB.new(File.read(creds)).result)
         
     | 
| 
      
 91 
     | 
    
         
            +
                    when Hash
         
     | 
| 
      
 92 
     | 
    
         
            +
                      creds
         
     | 
| 
      
 93 
     | 
    
         
            +
                    else
         
     | 
| 
      
 94 
     | 
    
         
            +
                      raise ArgumentError, "Credentials are not a path, file, proc, or hash."
         
     | 
| 
      
 95 
     | 
    
         
            +
                    end
         
     | 
| 
      
 96 
     | 
    
         
            +
                  end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                  def atompub_attachment(style_name = default_style)
         
     | 
| 
      
 99 
     | 
    
         
            +
                    PaperclipAtompub::Attachment.where(:style => style_name,
         
     | 
| 
      
 100 
     | 
    
         
            +
                                                       :instance_type => self.instance.class.name,
         
     | 
| 
      
 101 
     | 
    
         
            +
                                                       :instance_id => self.instance.id,
         
     | 
| 
      
 102 
     | 
    
         
            +
                                                       :attachment_name => self.name).first_or_initialize
         
     | 
| 
      
 103 
     | 
    
         
            +
                  end
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                  def atompub_entry(style_name = default_style)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    entry = atompub_attachment(style_name)
         
     | 
| 
      
 107 
     | 
    
         
            +
                    return nil if entry.new_record?
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                    return atompub_client.get_entry(entry.resource_uri)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  rescue ::Atompub::RequestError
         
     | 
| 
      
 111 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
              end
         
     | 
| 
      
 116 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,157 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: paperclip-atompub
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Yuichi Takeuchi
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-11-08 00:00:00.000000000 Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 14 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 15 
     | 
    
         
            +
              name: rails
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 17 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 18 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 19 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 20 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 21 
     | 
    
         
            +
                    version: 3.2.8
         
     | 
| 
      
 22 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 23 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 25 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 26 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: 3.2.8
         
     | 
| 
      
 30 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 31 
     | 
    
         
            +
              name: paperclip
         
     | 
| 
      
 32 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 33 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 34 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 35 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 36 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 37 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 38 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 39 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 40 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 41 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 42 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 43 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 44 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 45 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 46 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 47 
     | 
    
         
            +
              name: atomutil
         
     | 
| 
      
 48 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 49 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 50 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 51 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 52 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 53 
     | 
    
         
            +
                    version: 0.1.3
         
     | 
| 
      
 54 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 55 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 56 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 57 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 58 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 59 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 60 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 61 
     | 
    
         
            +
                    version: 0.1.3
         
     | 
| 
      
 62 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 63 
     | 
    
         
            +
              name: sqlite3
         
     | 
| 
      
 64 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 65 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 66 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 67 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 68 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 69 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 70 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 71 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 72 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 73 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 74 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 75 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 76 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 77 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 78 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 79 
     | 
    
         
            +
              name: rspec-rails
         
     | 
| 
      
 80 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 81 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 82 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 83 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 84 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 85 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 86 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 87 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 88 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 89 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 90 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 91 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 92 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 93 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 94 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 95 
     | 
    
         
            +
              name: settingslogic
         
     | 
| 
      
 96 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 97 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 98 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 99 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 100 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 101 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 102 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 103 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 104 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 105 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 106 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 107 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 108 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 109 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 110 
     | 
    
         
            +
            description: Adds Atompub Media Resource strage support for the Paperclip
         
     | 
| 
      
 111 
     | 
    
         
            +
            email:
         
     | 
| 
      
 112 
     | 
    
         
            +
            - uzuki05@takeyu-web.com
         
     | 
| 
      
 113 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 114 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 115 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 116 
     | 
    
         
            +
            files:
         
     | 
| 
      
 117 
     | 
    
         
            +
            - app/models/paperclip_atompub/attachment.rb
         
     | 
| 
      
 118 
     | 
    
         
            +
            - app/controllers/paperclip-atompub/application_controller.rb
         
     | 
| 
      
 119 
     | 
    
         
            +
            - app/assets/stylesheets/paperclip-atompub/application.css
         
     | 
| 
      
 120 
     | 
    
         
            +
            - app/assets/javascripts/paperclip-atompub/application.js
         
     | 
| 
      
 121 
     | 
    
         
            +
            - app/views/layouts/paperclip-atompub/application.html.erb
         
     | 
| 
      
 122 
     | 
    
         
            +
            - app/helpers/paperclip-atompub/application_helper.rb
         
     | 
| 
      
 123 
     | 
    
         
            +
            - config/routes.rb
         
     | 
| 
      
 124 
     | 
    
         
            +
            - db/migrate/20121108051952_create_paperclip_atompub_attachments.rb
         
     | 
| 
      
 125 
     | 
    
         
            +
            - lib/paperclip-atompub/engine.rb
         
     | 
| 
      
 126 
     | 
    
         
            +
            - lib/paperclip-atompub/version.rb
         
     | 
| 
      
 127 
     | 
    
         
            +
            - lib/paperclip-atompub.rb
         
     | 
| 
      
 128 
     | 
    
         
            +
            - lib/tasks/paperclip-atompub_tasks.rake
         
     | 
| 
      
 129 
     | 
    
         
            +
            - lib/paperclip/storage/atompub.rb
         
     | 
| 
      
 130 
     | 
    
         
            +
            - MIT-LICENSE
         
     | 
| 
      
 131 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 132 
     | 
    
         
            +
            - README.rdoc
         
     | 
| 
      
 133 
     | 
    
         
            +
            homepage: https://github.com/uzuki05/paperclip-atompub
         
     | 
| 
      
 134 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 135 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 136 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 137 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 138 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 139 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 140 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 141 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 142 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 143 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 144 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 145 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 146 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 147 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 148 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 149 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 150 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 151 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 152 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 153 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
      
 154 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 155 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 156 
     | 
    
         
            +
            summary: Adds Atompub Media Resource strage support for the Paperclip
         
     | 
| 
      
 157 
     | 
    
         
            +
            test_files: []
         
     |