devise-acquirable 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 772d26458e235d52ee8e5db2867f89c526d02383bff8617526af97c06eff5616
4
+ data.tar.gz: 19c66fa1669a99d4c85e7decd4cca051d35b820242622788967694a724a525bc
5
+ SHA512:
6
+ metadata.gz: 5081f59d6a54e01c78ef0212fc28117145ce823976051989b68c34df0b6edcc2fd28afbb00a1484a1e286eb08164d4d803e0f3cc43ffe19b5ff85d9245c2bd78
7
+ data.tar.gz: a06f1b7febef3d399f0a977e627a381b0c403a1f42c66a76dc802d0f05708cf46605698e395bcb217cfa467e64efb907a6c8d69af56454744eab280463e2aa53
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in devise-acquirable.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop', require: false
11
+ gem 'rubocop-rake', require: false
12
+ gem 'rubocop-rspec', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,130 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise-acquirable (0.1.0)
5
+ devise (~> 4.0, >= 4.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (7.0.3)
11
+ actionview (= 7.0.3)
12
+ activesupport (= 7.0.3)
13
+ rack (~> 2.0, >= 2.2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
+ actionview (7.0.3)
18
+ activesupport (= 7.0.3)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activesupport (7.0.3)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 1.6, < 2)
26
+ minitest (>= 5.1)
27
+ tzinfo (~> 2.0)
28
+ ast (2.4.2)
29
+ bcrypt (3.1.18)
30
+ builder (3.2.4)
31
+ concurrent-ruby (1.1.10)
32
+ crass (1.0.6)
33
+ devise (4.8.1)
34
+ bcrypt (~> 3.0)
35
+ orm_adapter (~> 0.1)
36
+ railties (>= 4.1.0)
37
+ responders
38
+ warden (~> 1.2.3)
39
+ diff-lcs (1.5.0)
40
+ erubi (1.10.0)
41
+ i18n (1.10.0)
42
+ concurrent-ruby (~> 1.0)
43
+ json (2.6.2)
44
+ loofah (2.18.0)
45
+ crass (~> 1.0.2)
46
+ nokogiri (>= 1.5.9)
47
+ method_source (1.0.0)
48
+ mini_portile2 (2.8.0)
49
+ minitest (5.16.2)
50
+ nokogiri (1.13.6)
51
+ mini_portile2 (~> 2.8.0)
52
+ racc (~> 1.4)
53
+ orm_adapter (0.5.0)
54
+ parallel (1.22.1)
55
+ parser (3.1.2.0)
56
+ ast (~> 2.4.1)
57
+ racc (1.6.0)
58
+ rack (2.2.4)
59
+ rack-test (2.0.2)
60
+ rack (>= 1.3)
61
+ rails-dom-testing (2.0.3)
62
+ activesupport (>= 4.2.0)
63
+ nokogiri (>= 1.6)
64
+ rails-html-sanitizer (1.4.3)
65
+ loofah (~> 2.3)
66
+ railties (7.0.3)
67
+ actionpack (= 7.0.3)
68
+ activesupport (= 7.0.3)
69
+ method_source
70
+ rake (>= 12.2)
71
+ thor (~> 1.0)
72
+ zeitwerk (~> 2.5)
73
+ rainbow (3.1.1)
74
+ rake (12.3.3)
75
+ regexp_parser (2.5.0)
76
+ responders (3.0.1)
77
+ actionpack (>= 5.0)
78
+ railties (>= 5.0)
79
+ rexml (3.2.5)
80
+ rspec (3.11.0)
81
+ rspec-core (~> 3.11.0)
82
+ rspec-expectations (~> 3.11.0)
83
+ rspec-mocks (~> 3.11.0)
84
+ rspec-core (3.11.0)
85
+ rspec-support (~> 3.11.0)
86
+ rspec-expectations (3.11.0)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.11.0)
89
+ rspec-mocks (3.11.1)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.11.0)
92
+ rspec-support (3.11.0)
93
+ rubocop (1.31.1)
94
+ json (~> 2.3)
95
+ parallel (~> 1.10)
96
+ parser (>= 3.1.0.0)
97
+ rainbow (>= 2.2.2, < 4.0)
98
+ regexp_parser (>= 1.8, < 3.0)
99
+ rexml (>= 3.2.5, < 4.0)
100
+ rubocop-ast (>= 1.18.0, < 2.0)
101
+ ruby-progressbar (~> 1.7)
102
+ unicode-display_width (>= 1.4.0, < 3.0)
103
+ rubocop-ast (1.18.0)
104
+ parser (>= 3.1.1.0)
105
+ rubocop-rake (0.6.0)
106
+ rubocop (~> 1.0)
107
+ rubocop-rspec (2.12.1)
108
+ rubocop (~> 1.31)
109
+ ruby-progressbar (1.11.0)
110
+ thor (1.2.1)
111
+ tzinfo (2.0.4)
112
+ concurrent-ruby (~> 1.0)
113
+ unicode-display_width (2.2.0)
114
+ warden (1.2.9)
115
+ rack (>= 2.0.9)
116
+ zeitwerk (2.6.0)
117
+
118
+ PLATFORMS
119
+ ruby
120
+
121
+ DEPENDENCIES
122
+ devise-acquirable!
123
+ rake (~> 12.0)
124
+ rspec (~> 3.0)
125
+ rubocop
126
+ rubocop-rake
127
+ rubocop-rspec
128
+
129
+ BUNDLED WITH
130
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Simon Lehmann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Devise::Acquirable
2
+
3
+ > This project started as a fork of nate's [n8/devise_marketable](https://github.com/n8/devise_marketable) project.
4
+
5
+ Acquirable lets [Devise](https://github.com/plataformatec/devise) implementers easily store where a user came from and where they were going in your Rails app.
6
+
7
+ With Acquirable, Devise will automatically create two cookies for your users when they first visit your app, the referring_url (where they came from) and the landing_url (where they landed). When the user registers with your application, the values in those cookies are stored alongside your user data.
8
+
9
+ ## Installation
10
+
11
+ 1. Add 'devise-acquirable' to your Gemfile.
12
+
13
+ ```ruby
14
+ gem 'devise-acquirable'
15
+ ```
16
+
17
+ 2. Run `bundle install`
18
+ 3. Add the marketing fields to your user table:
19
+
20
+ ```shell
21
+ rails g devise-acquirable MODEL
22
+ ```
23
+
24
+ MODEL is probably `User`. It's what you attach Devise to. (e.g. User, Admin, Account)
25
+
26
+ ```shell
27
+ rails g devise-acquirable User
28
+ ```
29
+
30
+ 4. Run your migration
31
+
32
+ ```shell
33
+ bundle exec rails db:migrate
34
+ ```
35
+
36
+ 5. Check `:acquirable` was added to the `devise` call in your model by the `devise:acquirable` generator
37
+
38
+ ```ruby
39
+ devise :database_authenticatable, ..., :acquirable
40
+ ```
41
+
42
+ 6. Restart your server
43
+
44
+ That's it. You now have some very powerful data: where your best customers come from, what traffic sources are your most lucrative, what on your website converts the best, what people are most interested in, etc.
45
+
46
+ ## Feedback
47
+
48
+ [Source code available on Github](https://github.com/simonlehmann/devise-acquirable). Feedback and pull requests are greatly appreciated.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'devise/acquirable/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'devise-acquirable'
9
+ spec.version = Devise::Acquirable::VERSION
10
+ spec.authors = ['Simon Lehmann']
11
+ spec.email = ['slehmann36@gmail.com']
12
+ spec.description = 'Easily capture and store marketing data during Devise user onboarding.'
13
+ spec.summary = 'Easily capture and store marketing data during Devise user onboarding.'
14
+ spec.homepage = 'https://github.com/simonlehmann/devise-acquirable'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'devise', '~> 4.0', '>= 4.0.0'
23
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Devise
4
+ module Models
5
+ module Acquirable
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Devise
4
+ module Acquirable
5
+ VERSION = '0.1.1'
6
+ end
7
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'devise'
4
+ require 'devise/acquirable/version'
5
+
6
+ Devise.add_module :acquirable, model: 'devise/acquirable/model', controller: :registrations
7
+
8
+ module Devise
9
+ module Acquirable
10
+ module Controller
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ before_action :set_tracking_cookies
15
+ end
16
+
17
+ def set_tracking_cookies
18
+ cookies[:referring_url] =
19
+ { value: request.env['HTTP_REFERER'], expires: 90.days.from_now } if cookies[:referring_url].blank?
20
+
21
+ cookies[:landing_url] =
22
+ { value: request.url, expires: 90.days.from_now } if cookies[:landing_url].blank?
23
+ end
24
+ end
25
+
26
+ module RegistrationsController
27
+ extend ActiveSupport::Concern
28
+
29
+ included do
30
+ alias_method :devise_build_resource, :build_resource
31
+ def build_resource(hash = nil)
32
+ custom_build_resource(hash)
33
+ end
34
+ end
35
+
36
+ def custom_build_resource(hash = nil)
37
+ devise_build_resource(hash)
38
+
39
+ set_marketing_attributes if devise_mapping.acquirable?
40
+
41
+ resource
42
+ end
43
+
44
+ def set_marketing_attributes
45
+ resource.referring_url = cookies[:referring_url]
46
+ resource.landing_url = cookies[:landing_url]
47
+ end
48
+ end
49
+
50
+ class Engine < ::Rails::Engine
51
+ ActiveSupport.on_load(:action_controller) do
52
+ include Devise::Acquirable::Controller
53
+ end
54
+
55
+ config.to_prepare do
56
+ Devise::RegistrationsController.include Devise::Acquirable::RegistrationsController
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/active_record'
4
+
5
+ module Devise
6
+ module Generators
7
+ class AcquirableGenerator < ActiveRecord::Generators::Base
8
+ source_root File.expand_path('templates', __dir__)
9
+
10
+ desc 'Generate migration for ActiveRecord and add :acquirable directive in the given model.'
11
+
12
+ def copy_migration
13
+ migration_template 'migration.rb', "db/migrate/devise_acquirable_add_to_#{table_name}.rb",
14
+ migration_version: migration_version
15
+ end
16
+
17
+ def inject_devise_acquirable_content
18
+ path = File.join('app', 'models', "#{file_path}.rb")
19
+ inject_into_file(path, 'acquirable, :', after: 'devise :') if File.exist?(path)
20
+ end
21
+
22
+ private
23
+
24
+ def versioned_migrations?
25
+ Rails::VERSION::MAJOR >= 5
26
+ end
27
+
28
+ def migration_version
29
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if versioned_migrations?
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ class DeviseAcquirableAddTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
+ def self.up
3
+ add_column :<%= table_name %>, :referring_url, :text
4
+ add_column :<%= table_name %>, :landing_url, :text
5
+ end
6
+
7
+ def self.down
8
+ remove_column :<%= table_name %>, :referring_url
9
+ remove_column :<%= table_name %>, :landing_url
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Devise::Acquirable do
4
+ it 'has a version number' do
5
+ expect(Devise::Acquirable::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful'
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'devise/acquirable'
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = '.rspec_status'
9
+
10
+ # Disable RSpec exposing methods globally on `Module` and `main`
11
+ config.disable_monkey_patching!
12
+
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-acquirable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Lehmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.0.0
33
+ description: Easily capture and store marketing data during Devise user onboarding.
34
+ email:
35
+ - slehmann36@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".gitignore"
41
+ - ".rspec"
42
+ - Gemfile
43
+ - Gemfile.lock
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - devise-acquirable.gemspec
48
+ - lib/devise/acquirable.rb
49
+ - lib/devise/acquirable/model.rb
50
+ - lib/devise/acquirable/version.rb
51
+ - lib/generators/devise/acquirable_generator.rb
52
+ - lib/generators/devise/templates/migration.rb
53
+ - spec/devise/acquirable_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: https://github.com/simonlehmann/devise-acquirable
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.1.6
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Easily capture and store marketing data during Devise user onboarding.
78
+ test_files:
79
+ - spec/devise/acquirable_spec.rb
80
+ - spec/spec_helper.rb