adva-cache 0.0.3 → 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.
- data/lib/adva-cache.rb +1 -0
 - data/lib/adva/cache.rb +20 -0
 - data/lib/adva/cache/responder.rb +7 -0
 - data/lib/adva/cache/responder/purge.rb +20 -0
 - data/lib/adva_cache/version.rb +3 -0
 - data/lib/testing/step_definitions.rb +55 -0
 - metadata +10 -5
 - data/lib/bundler/repository.rb +0 -118
 
    
        data/lib/adva-cache.rb
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'adva/cache'
         
     | 
    
        data/lib/adva/cache.rb
    ADDED
    
    | 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'adva/core'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rack/cache'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rack/cache/purge'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rack/cache/tags'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module Adva
         
     | 
| 
      
 8 
     | 
    
         
            +
              class Cache < ::Rails::Engine
         
     | 
| 
      
 9 
     | 
    
         
            +
                autoload :Responder, 'adva/cache/responder'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                include Adva::Engine
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                # TODO [config] add config vars to specify rack-cache storage uris
         
     | 
| 
      
 14 
     | 
    
         
            +
                config.app_middleware.insert_after 'Rails::Rack::Logger', ::Rack::Cache
         
     | 
| 
      
 15 
     | 
    
         
            +
                config.app_middleware.insert_after 'Rack::Cache', ::Rack::Cache::Purge
         
     | 
| 
      
 16 
     | 
    
         
            +
                config.app_middleware.insert_after 'Rack::Cache::Purge', ::Rack::Cache::Tags
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            Adva::Responder.send(:include, Adva::Cache::Responder::Purge)
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Adva
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Cache
         
     | 
| 
      
 3 
     | 
    
         
            +
                module Responder
         
     | 
| 
      
 4 
     | 
    
         
            +
                  module Purge
         
     | 
| 
      
 5 
     | 
    
         
            +
                    delegate :purge,  :to => :controller
         
     | 
| 
      
 6 
     | 
    
         
            +
                    delegate :purge?, :to => :'controller.class'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                    def to_html
         
     | 
| 
      
 9 
     | 
    
         
            +
                      super.tap { purge(purge_resources) if purge?(params[:action]) }
         
     | 
| 
      
 10 
     | 
    
         
            +
                    end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    protected
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                      def purge_resources
         
     | 
| 
      
 15 
     | 
    
         
            +
                        resource.respond_to?(:persisted?) ? [resource] : []
         
     | 
| 
      
 16 
     | 
    
         
            +
                      end
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            When /^(?:|I )have visited (.+)$/ do |page|
         
     | 
| 
      
 2 
     | 
    
         
            +
              visit path_to(page)
         
     | 
| 
      
 3 
     | 
    
         
            +
              follow_redirect! if redirect?
         
     | 
| 
      
 4 
     | 
    
         
            +
            end
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            When /^the following urls are tagged:$/ do |table|
         
     | 
| 
      
 7 
     | 
    
         
            +
              table.hashes.each do |attributes|
         
     | 
| 
      
 8 
     | 
    
         
            +
                url = "http://www.example.com#{attributes[:url]}"
         
     | 
| 
      
 9 
     | 
    
         
            +
                attributes[:tags].split(',').map(&:strip).each do |tag|
         
     | 
| 
      
 10 
     | 
    
         
            +
                  Rack::Cache::Tags::Store::ActiveRecord::Tagging.create!(:tag => tag, :url => url)
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            Then /^the following urls should be tagged:$/ do |table|
         
     | 
| 
      
 16 
     | 
    
         
            +
              table.hashes.each do |hash|
         
     | 
| 
      
 17 
     | 
    
         
            +
                url = "http://www.example.com#{hash[:url]}"
         
     | 
| 
      
 18 
     | 
    
         
            +
                actual = Rack::Cache::Tags::Store::ActiveRecord::Tagging.where(:url => url).map(&:tag)
         
     | 
| 
      
 19 
     | 
    
         
            +
                expected = hash[:tags].split(',').map(&:strip)
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal expected, expected & actual
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            Webrat::Session.class_eval do
         
     | 
| 
      
 25 
     | 
    
         
            +
              cattr_accessor :follow_redirects
         
     | 
| 
      
 26 
     | 
    
         
            +
              self.follow_redirects = true
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def internal_redirect_with_skipping?
         
     | 
| 
      
 29 
     | 
    
         
            +
                follow_redirects && internal_redirect_without_skipping?
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
              alias_method_chain :internal_redirect?, :skipping
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            Before do
         
     | 
| 
      
 35 
     | 
    
         
            +
              Webrat::Session.follow_redirects = true
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            When /I don't follow any http redirects/ do
         
     | 
| 
      
 39 
     | 
    
         
            +
              Webrat::Session.follow_redirects = false
         
     | 
| 
      
 40 
     | 
    
         
            +
            end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            Then /^it should purge cache entries tagged: (.+)$/ do |tags|
         
     | 
| 
      
 43 
     | 
    
         
            +
              expected = tags.split(',').map(&:strip)
         
     | 
| 
      
 44 
     | 
    
         
            +
              actual = response.headers[Rack::Cache::Tags::PURGE_TAGS_HEADER]
         
     | 
| 
      
 45 
     | 
    
         
            +
              assert actual, 'no purge tags headers found'
         
     | 
| 
      
 46 
     | 
    
         
            +
              assert_equal expected.sort, actual.split("\n").sort
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            Then /^it should purge the cache entries: (.+)$/ do |urls|
         
     | 
| 
      
 50 
     | 
    
         
            +
              expected = urls.split(',').map(&:strip).sort
         
     | 
| 
      
 51 
     | 
    
         
            +
              actual = response.headers[Rack::Cache::Purge::PURGE_HEADER]
         
     | 
| 
      
 52 
     | 
    
         
            +
              assert actual, 'no purge headers found'
         
     | 
| 
      
 53 
     | 
    
         
            +
              actual = actual.split("\n").map { |url| url.sub('http://www.example.com', '') }.sort
         
     | 
| 
      
 54 
     | 
    
         
            +
              assert_equal expected, actual, "did not purge the expected urls.\n expected: #{expected.inspect}\n actual: #{actual.inspect}"
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: adva-cache
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 23
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 4
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.0.4
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Sven Fuchs
         
     | 
| 
         @@ -15,7 +15,7 @@ autorequire: 
     | 
|
| 
       15 
15 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
16 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2010- 
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2010-12-03 00:00:00 +01:00
         
     | 
| 
       19 
19 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -89,7 +89,12 @@ extensions: [] 
     | 
|
| 
       89 
89 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
            files: 
         
     | 
| 
       92 
     | 
    
         
            -
            - lib/ 
     | 
| 
      
 92 
     | 
    
         
            +
            - lib/adva-cache.rb
         
     | 
| 
      
 93 
     | 
    
         
            +
            - lib/adva/cache/responder/purge.rb
         
     | 
| 
      
 94 
     | 
    
         
            +
            - lib/adva/cache/responder.rb
         
     | 
| 
      
 95 
     | 
    
         
            +
            - lib/adva/cache.rb
         
     | 
| 
      
 96 
     | 
    
         
            +
            - lib/adva_cache/version.rb
         
     | 
| 
      
 97 
     | 
    
         
            +
            - lib/testing/step_definitions.rb
         
     | 
| 
       93 
98 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       94 
99 
     | 
    
         
             
            homepage: http://github.com/svenfuchs/adva-cms2
         
     | 
| 
       95 
100 
     | 
    
         
             
            licenses: []
         
     | 
    
        data/lib/bundler/repository.rb
    DELETED
    
    | 
         @@ -1,118 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'pathname'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            # Bundler gemfile support for local/remote workspaces/repositories for work in
         
     | 
| 
       4 
     | 
    
         
            -
            # development teams.
         
     | 
| 
       5 
     | 
    
         
            -
            #
         
     | 
| 
       6 
     | 
    
         
            -
            # Usage:
         
     | 
| 
       7 
     | 
    
         
            -
            #
         
     | 
| 
       8 
     | 
    
         
            -
            #   # define paths to be searched for repositories:
         
     | 
| 
       9 
     | 
    
         
            -
            #   workspace '~/.projects ~/Development/{projects,work}'
         
     | 
| 
       10 
     | 
    
         
            -
            #
         
     | 
| 
       11 
     | 
    
         
            -
            #   # define developer preferences for using local or remote repositories (uses ENV['user']):
         
     | 
| 
       12 
     | 
    
         
            -
            #   developer :sven, :prefer => :local
         
     | 
| 
       13 
     | 
    
         
            -
            #
         
     | 
| 
       14 
     | 
    
         
            -
            #   # define repositories to be used for particular gems:
         
     | 
| 
       15 
     | 
    
         
            -
            #   adva_cms  = repository('adva-cms2', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de')
         
     | 
| 
       16 
     | 
    
         
            -
            #   adva_shop = repository('adva-shop', :source => :local)
         
     | 
| 
       17 
     | 
    
         
            -
            #
         
     | 
| 
       18 
     | 
    
         
            -
            #   # now use repositories to define gems:
         
     | 
| 
       19 
     | 
    
         
            -
            #   adva_cms.gem  'adva-core'
         
     | 
| 
       20 
     | 
    
         
            -
            #   adva_shop.gem 'adva-catalog'
         
     | 
| 
       21 
     | 
    
         
            -
            #
         
     | 
| 
       22 
     | 
    
         
            -
            #   # The gem definition will now be proxied to Bundler with arguments according
         
     | 
| 
       23 
     | 
    
         
            -
            #   # to the setup defined earlier. E.g. as:
         
     | 
| 
       24 
     | 
    
         
            -
            #
         
     | 
| 
       25 
     | 
    
         
            -
            #   gem 'adva-core', :path => 'Development/projects/adva-cms2/adva-core'                 # for developer 'sven'
         
     | 
| 
       26 
     | 
    
         
            -
            #   gem 'adva-core', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de' # for other developers
         
     | 
| 
       27 
     | 
    
         
            -
            #   gem 'adva-catalog', :path => 'Development/projects/adva-shop/adva-catalog'           # for all developers
         
     | 
| 
       28 
     | 
    
         
            -
            #
         
     | 
| 
       29 
     | 
    
         
            -
            #  One can also set an environment variable FORCE_REMOTE which will force remote
         
     | 
| 
       30 
     | 
    
         
            -
            #  repositories to be used *except* when a repository was defined with :source => :local
         
     | 
| 
       31 
     | 
    
         
            -
            #  which always forces the local repository to be used.
         
     | 
| 
       32 
     | 
    
         
            -
            #
         
     | 
| 
       33 
     | 
    
         
            -
            class Repository
         
     | 
| 
       34 
     | 
    
         
            -
              class << self
         
     | 
| 
       35 
     | 
    
         
            -
                def paths
         
     | 
| 
       36 
     | 
    
         
            -
                  @paths ||= []
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                def path(*paths)
         
     | 
| 
       40 
     | 
    
         
            -
                  paths.join(' ').split(' ').each do |path|
         
     | 
| 
       41 
     | 
    
         
            -
                    self.paths.concat(Pathname.glob(File.expand_path(path)))
         
     | 
| 
       42 
     | 
    
         
            -
                  end
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                def developer(name, preferences)
         
     | 
| 
       46 
     | 
    
         
            -
                  developers[name] = preferences
         
     | 
| 
       47 
     | 
    
         
            -
                  workspaces(preferences[:workspace])
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                def current_developer
         
     | 
| 
       51 
     | 
    
         
            -
                  developers[ENV['USER'].to_sym] || {}
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                def developers(developers = nil)
         
     | 
| 
       55 
     | 
    
         
            -
                  @developers ||= {}
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              class Gem < Array
         
     | 
| 
       60 
     | 
    
         
            -
                def initialize(name, repository)
         
     | 
| 
       61 
     | 
    
         
            -
                  if repository.local?
         
     | 
| 
       62 
     | 
    
         
            -
                    sub_path = repository.path.join(name)
         
     | 
| 
       63 
     | 
    
         
            -
                    super([name, { :path => sub_path.exist? ? sub_path.to_s : repository.path.to_s }])
         
     | 
| 
       64 
     | 
    
         
            -
                  else
         
     | 
| 
       65 
     | 
    
         
            -
                    super([name, repository.options.dup])
         
     | 
| 
       66 
     | 
    
         
            -
                  end
         
     | 
| 
       67 
     | 
    
         
            -
                end
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              attr_reader :bundler, :name, :options, :source
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
              def initialize(bundler, name, options)
         
     | 
| 
       73 
     | 
    
         
            -
                @bundler = bundler
         
     | 
| 
       74 
     | 
    
         
            -
                @name    = name
         
     | 
| 
       75 
     | 
    
         
            -
                @source  = options.delete(:source)
         
     | 
| 
       76 
     | 
    
         
            -
                @options = options
         
     | 
| 
       77 
     | 
    
         
            -
              end
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
              def gem(name)
         
     | 
| 
       80 
     | 
    
         
            -
                bundler.gem(*Gem.new(name, self))
         
     | 
| 
       81 
     | 
    
         
            -
              end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
              def local?
         
     | 
| 
       84 
     | 
    
         
            -
                source == :local # && path
         
     | 
| 
       85 
     | 
    
         
            -
              end
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
              def source
         
     | 
| 
       88 
     | 
    
         
            -
                @source ||= forced_source || preferred_source || :remote
         
     | 
| 
       89 
     | 
    
         
            -
              end
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
              def forced_source
         
     | 
| 
       92 
     | 
    
         
            -
                :remote if ENV['FORCE_REMOTE']
         
     | 
| 
       93 
     | 
    
         
            -
              end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
              def preferred_source
         
     | 
| 
       96 
     | 
    
         
            -
                self.class.current_developer[:prefer] || self.class.current_developer[name.to_sym]
         
     | 
| 
       97 
     | 
    
         
            -
              end
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
              def path
         
     | 
| 
       100 
     | 
    
         
            -
                @path ||= begin
         
     | 
| 
       101 
     | 
    
         
            -
                  path = self.class.paths.detect { |path| path.join(name).exist? }
         
     | 
| 
       102 
     | 
    
         
            -
                  path ? path.join(name) : Pathname.new('.')
         
     | 
| 
       103 
     | 
    
         
            -
                end
         
     | 
| 
       104 
     | 
    
         
            -
              end
         
     | 
| 
       105 
     | 
    
         
            -
            end
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
            def workspace(*paths)
         
     | 
| 
       108 
     | 
    
         
            -
              Repository.path(*paths)
         
     | 
| 
       109 
     | 
    
         
            -
            end
         
     | 
| 
       110 
     | 
    
         
            -
            alias :workspaces :workspace
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
            def developer(name, preferences)
         
     | 
| 
       113 
     | 
    
         
            -
              Repository.developer(name, preferences)
         
     | 
| 
       114 
     | 
    
         
            -
            end
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
            def repository(*args)
         
     | 
| 
       117 
     | 
    
         
            -
              Repository.new(self, *args)
         
     | 
| 
       118 
     | 
    
         
            -
            end
         
     |