persist_campaign 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDM4YWQ4N2YyY2FiY2UzZjA0ZjkyZTYyM2IxNzFkMDE4ZTY5MGI2ZQ==
5
+ data.tar.gz: !binary |-
6
+ MjdhMGM2YzAxYTMzMTRkYTg2NzgxMzNmYTQ4NWMwMTg4NzM5NTM0Yw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWJmMmEzNGMxNDhjMDJmYTJjZTc5NjcxZTVmNjhiNjhjZDI5ZThmNGIxZDUw
10
+ MWE0ZDYwOTA2NGE0NDc5MjkwOWVhZWEyYWJkYTBjOWUyNjEwYzA0MWY5OWIw
11
+ MjY3NWJlOGU4MjM0ZGRhY2IzZWZjOGJkN2M4NTYzMDE1NWI5OTE=
12
+ data.tar.gz: !binary |-
13
+ NTJlMTkzZDgxZjAyN2UwZTZlODU4YjI2NDgzMDI0NjEwMTViZjM3MTFjNTI0
14
+ YzExNjMxYjIyMWU4NzQzNzEyMjI4ZDdmMWFmYzRmZWE4ZWJkYWIzZWQ1NTg5
15
+ OGIzY2NmYzc1ZjIxOWJiMjk1NjE4ZDc1MzVlZmQ3NmQzMmRjM2M=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/dummy/log
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in persist_campaign.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andy Dust
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # PersistCampaign
2
+
3
+ Persist campaign parameters - such as utm_campaign, utm_source, etc - on Rails redirect_to.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+ ```ruby
9
+ gem 'persist_campaign'
10
+ ```
11
+
12
+ And then execute:
13
+ ```sh
14
+ $ bundle
15
+ ```
16
+
17
+ ## Default persisted keys
18
+
19
+ * utm_campaign
20
+ * utm_source
21
+ * utm_medium
22
+ * utm_content
23
+ * utm_term
24
+ * gclid (for Google Adwords)
25
+
26
+ ## Configure additional keys
27
+
28
+ You can append to the key array in a configuration block. There is an install generator to create
29
+ the initializer file.
30
+
31
+ ```sh
32
+ rails g persist_campaign:install
33
+ ```
34
+
35
+ Edit the initializer to append other keys:
36
+
37
+ ```ruby
38
+ PersistCampaign.configure do |config|
39
+ config.keys += ['foo']
40
+ end
41
+ ```
42
+
43
+ ## Testing
44
+ ```sh
45
+ rake
46
+ ```
47
+
48
+ ## Credits
49
+ Thanks to [ndp](http://github.com/ndp)'s [save-the-campaign](http://github.com/save-the-campaign) gem for
50
+ providing the solution to patching Rail's redirect_to implemention. His solution is reproduced here under the
51
+ MIT license.
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( http://github.com/mubi/persist_campaign/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ desc 'Runs the specs'
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ module PersistCampaign
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :name, type: :string, default: 'persist_campaign'
6
+
7
+ def create_initializer_file
8
+ template 'initializer.rb', "config/initializers/#{name}.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ PeristCampaign.configure do |config|
2
+ # add addtional param keys to persist
3
+ # config.keys += [:foo, :bar]
4
+ end
@@ -0,0 +1,10 @@
1
+ module PersistCampaign
2
+ class Config
3
+ attr_accessor :keys
4
+ DEFAULT_KEYS = %w{utm_campaign utm_source utm_term utm_medium utm_content gclid}
5
+
6
+ def initialize
7
+ @keys = DEFAULT_KEYS
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module PersistCampaign
2
+ module Controller
3
+ def self.included base
4
+ base.send :include, InstanceMethods
5
+ base.alias_method_chain :_compute_redirect_to_location, :persist_campaign_params
6
+ end
7
+
8
+ module InstanceMethods
9
+ # Solution provided by ndp's save-the-campaign gem (http://github.com/ndp/save-the-campaign),
10
+ # reproduced here under the MIT license
11
+ def _compute_redirect_to_location_with_persist_campaign_params(options = {})
12
+ keys = PersistCampaign.config.keys.map(&:to_s)
13
+ to_persist = request.params.slice(*keys)
14
+ url = _compute_redirect_to_location_without_persist_campaign_params(options)
15
+
16
+ unless to_persist.empty?
17
+ url << (url =~ /\?/ ? '&' : '?')
18
+ url << to_persist.to_param
19
+ end
20
+
21
+ url
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module PersistCampaign
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'persist_campaign.controller' do
4
+ ActiveSupport.on_load(:action_controller) do
5
+ include PersistCampaign::Controller
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module PersistCampaign
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'persist_campaign/version'
2
+ require 'persist_campaign/config'
3
+ require 'persist_campaign/controller'
4
+
5
+ module PersistCampaign
6
+ def self.config
7
+ @config ||= PersistCampaign::Config.new
8
+ end
9
+
10
+ def self.configure(&block)
11
+ yield(config) if block_given?
12
+ end
13
+ end
14
+
15
+ require 'persist_campaign/railtie' if defined?(Rails)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'persist_campaign/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "persist_campaign"
8
+ spec.version = PersistCampaign::VERSION
9
+ spec.authors = ["Andy Dust"]
10
+ spec.email = ["adust@mubi.com"]
11
+ spec.summary = %q{Persist campaign parameters - such as utm_campaign, utm_source, etc - on Rails redirect_to.}
12
+ spec.description = %q{This Rails gem allows you to persist analytics parameters through redirects. By default its
13
+ persists utm_campaign, utm_source, utm_term, utm_medium, utm_content and gclid (for Google Adwords).
14
+ Additional param keys can be configured.}
15
+ spec.homepage = "http://github.com/mubi/persist_campaign"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency 'rails', '>= 3.1.12'
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency 'rspec-rails', '~> 2.14'
27
+ spec.add_development_dependency 'generator_spec', '~> 0.9.2'
28
+ end
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '~> 3.1.12'
4
+ gem 'persist_campaign', :path => '../../'
@@ -0,0 +1,13 @@
1
+ class ExampleController < ActionController::Base
2
+ def foo
3
+ redirect_to controller: :example, action: :bar
4
+ end
5
+
6
+ def action_with_params
7
+ redirect_to controller: :example, action: :bar, hello: 'world'
8
+ end
9
+
10
+ def bar
11
+ render nothing: true
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "action_mailer/railtie"
5
+
6
+ Bundler.require(*Rails.groups)
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ end
11
+ end
12
+
13
+ Rails.application.configure do
14
+ config.eager_load = false
15
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ get ':controller(/:action(/:id))(.:format)'
3
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 94eaac6bd057e82a5abb95fdff9f9828cd7660267ee3435c97ab8a3aeb621ac375003b5ff1548bc8590ec5f63ea393783e755163e9308c0b87f3c01eb5553783
15
+
16
+ test:
17
+ secret_key_base: e1d13d4b689d5ed95eb2b03236260a3dd1e6e2123f8cd2951964846f9ba004d1d25de47f897437c79f6b9e354b7a1b8400d1b0ac4b85dcb72c720964e6060792
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'generator_spec'
3
+ require 'generators/persist_campaign/install_generator'
4
+
5
+ describe PersistCampaign::Generators::InstallGenerator do
6
+ include GeneratorSpec::TestCase
7
+ destination File.expand_path('../tmp', File.dirname(__FILE__))
8
+
9
+ before(:all) do
10
+ prepare_destination
11
+ end
12
+
13
+ it 'creates an initializer' do
14
+ run_generator
15
+ assert_file 'config/initializers/persist_campaign.rb'
16
+ end
17
+
18
+ context 'when a custom file name is provided as an argument' do
19
+ it 'creates an initializer with the specified file name' do
20
+ run_generator %w(foobar)
21
+ assert_file 'config/initializers/foobar.rb'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe PersistCampaign::Config do
4
+ subject(:config) { PersistCampaign::Config.new }
5
+
6
+ describe '.initialize' do
7
+ it 'assigns default param keys' do
8
+ expect(config.keys).to eq config.class::DEFAULT_KEYS
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe ExampleController, type: :controller do
4
+ before(:each) do
5
+ PersistCampaign.configure { |c| c.keys = %w{alpha beta} }
6
+ end
7
+ let(:params) { { alpha: '1', beta: '2' } }
8
+
9
+ it 'should persist specified params' do
10
+ get 'foo', params
11
+ expect(response).to redirect_to('/example/bar?alpha=1&beta=2')
12
+ end
13
+
14
+ it 'does not overwrite existing params' do
15
+ get 'action_with_params', params
16
+ expect(response).to redirect_to('/example/bar?hello=world&alpha=1&beta=2')
17
+ end
18
+
19
+ it 'ignores unconfigured params' do
20
+ get 'foo', params.merge(colour: 'red')
21
+ expect(response).to redirect_to('/example/bar?alpha=1&beta=2')
22
+ end
23
+
24
+ context 'with no params to persist' do
25
+ it 'redirects normally' do
26
+ get 'foo'
27
+ expect(response).to redirect_to('/example/bar')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PersistCampaign do
4
+ it 'should be valid' do
5
+ expect(PersistCampaign).to be_a(Module)
6
+ end
7
+
8
+ describe '.config' do
9
+ it 'returns the configuration instance' do
10
+ expect(PersistCampaign.config).to be_a(PersistCampaign::Config)
11
+ end
12
+ end
13
+
14
+ describe '.configure' do
15
+ it 'yields to the config instance' do
16
+ expect { |b| PersistCampaign.configure(&b) }.to yield_with_args(PersistCampaign::Config)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ Rails.backtrace_cleaner.remove_silencers!
7
+
8
+ RSpec.configure do |config|
9
+ config.infer_spec_type_from_file_location!
10
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: persist_campaign
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Dust
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.12
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.12
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: generator_spec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.2
83
+ description: ! "This Rails gem allows you to persist analytics parameters through
84
+ redirects. By default its\n persists utm_campaign, utm_source,
85
+ utm_term, utm_medium, utm_content and gclid (for Google Adwords).\n Additional
86
+ param keys can be configured."
87
+ email:
88
+ - adust@mubi.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - .gitignore
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/generators/persist_campaign/install_generator.rb
99
+ - lib/generators/persist_campaign/templates/initializer.rb
100
+ - lib/persist_campaign.rb
101
+ - lib/persist_campaign/config.rb
102
+ - lib/persist_campaign/controller.rb
103
+ - lib/persist_campaign/railtie.rb
104
+ - lib/persist_campaign/version.rb
105
+ - persist_campaign.gemspec
106
+ - spec/dummy/Gemfile
107
+ - spec/dummy/app/controllers/example_controller.rb
108
+ - spec/dummy/config.ru
109
+ - spec/dummy/config/application.rb
110
+ - spec/dummy/config/boot.rb
111
+ - spec/dummy/config/environment.rb
112
+ - spec/dummy/config/routes.rb
113
+ - spec/dummy/config/secrets.yml
114
+ - spec/generators/persist_campaign/install_generator_spec.rb
115
+ - spec/persist_campaign/config_spec.rb
116
+ - spec/persist_campaign/controller_spec.rb
117
+ - spec/persist_campaign_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: http://github.com/mubi/persist_campaign
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Persist campaign parameters - such as utm_campaign, utm_source, etc - on
143
+ Rails redirect_to.
144
+ test_files:
145
+ - spec/dummy/Gemfile
146
+ - spec/dummy/app/controllers/example_controller.rb
147
+ - spec/dummy/config.ru
148
+ - spec/dummy/config/application.rb
149
+ - spec/dummy/config/boot.rb
150
+ - spec/dummy/config/environment.rb
151
+ - spec/dummy/config/routes.rb
152
+ - spec/dummy/config/secrets.yml
153
+ - spec/generators/persist_campaign/install_generator_spec.rb
154
+ - spec/persist_campaign/config_spec.rb
155
+ - spec/persist_campaign/controller_spec.rb
156
+ - spec/persist_campaign_spec.rb
157
+ - spec/spec_helper.rb