profile_wizard 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +32 -0
- data/app/assets/config/profile_wizard_manifest.js +2 -0
- data/app/assets/javascripts/profile_wizard/application.js +15 -0
- data/app/assets/stylesheets/profile_wizard/application.css +15 -0
- data/app/controllers/profile_wizard/application_controller.rb +5 -0
- data/app/helpers/profile_wizard/application_helper.rb +4 -0
- data/app/jobs/profile_wizard/application_job.rb +4 -0
- data/app/mailers/profile_wizard/application_mailer.rb +6 -0
- data/app/models/profile_wizard/answer.rb +5 -0
- data/app/models/profile_wizard/application_record.rb +5 -0
- data/app/views/layouts/profile_wizard/application.html.erb +16 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20190307200449_create_profile_wizard_answers.rb +13 -0
- data/lib/profile_wizard.rb +5 -0
- data/lib/profile_wizard/engine.rb +11 -0
- data/lib/profile_wizard/models.rb +13 -0
- data/lib/profile_wizard/models/profile.rb +47 -0
- data/lib/profile_wizard/models/question.rb +20 -0
- data/lib/profile_wizard/models/step.rb +36 -0
- data/lib/profile_wizard/version.rb +3 -0
- data/lib/tasks/profile_wizard_tasks.rake +4 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 02c81da54cb7e78cc64ae4621ab644b206849462d28cce7c577058b14caccbe8
|
4
|
+
data.tar.gz: e8dc8792dd1a627aaf7ec1615b37dd93d6560de1f7cd62c3827e6008a793468e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8062aea215b606039b61d49555de0752f37cca8e405dde25a22cd537710063255a6d26a796142bdcf88e4e12fcf09b4d225500ab67057114d1ecd513c65c92d0
|
7
|
+
data.tar.gz: 8c861e06f7ff19e037bbe9ac29e5877c2c4aae1407321713b37f73b939ec0b55526174b4800eb08ed43bdc915a957e15a383ac2017b1fad0a7f52a7d52bc6216
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 BV Satyaramwq
|
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.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# ProfileWizard
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'profile_wizard'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install profile_wizard
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ProfileWizard'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
@@ -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 any plugin's vendor/assets/javascripts directory 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
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require activestorage
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Profile wizard</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag "profile_wizard/application", media: "all" %>
|
9
|
+
<%= javascript_include_tag "profile_wizard/application" %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<%= yield %>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateProfileWizardAnswers < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :profile_wizard_answers do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.json :data
|
6
|
+
t.references :record, null: false, polymorphic: true, index: false
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
|
10
|
+
t.index [ :record_type, :record_id, :name ], name: "index_profile_wizard_answers_uniqueness", unique: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative './models/profile'
|
2
|
+
require_relative './models/step'
|
3
|
+
require_relative './models/question'
|
4
|
+
|
5
|
+
module ProfileWizard
|
6
|
+
module Models
|
7
|
+
def profile_wizard(profile_attr, profile_schema, opts = {})
|
8
|
+
define_method(profile_attr) do
|
9
|
+
@profile_attr ||= ProfileWizard::Models::Profile.new profile_attr, profile_schema, self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ProfileWizard::Models
|
2
|
+
class Profile
|
3
|
+
attr_accessor :steps
|
4
|
+
|
5
|
+
def initialize(profile_attr, profile_schema, record)
|
6
|
+
@steps = {}
|
7
|
+
@profile_attr = profile_attr
|
8
|
+
@record = record
|
9
|
+
profile_schema.each do |step_key, step_schema|
|
10
|
+
self.class.class_eval do
|
11
|
+
define_method(step_key) do
|
12
|
+
@steps[step_key] ||= ProfileWizard::Models::Step.new(step_key, step_schema)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
send(step_key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
answer.data = json_answer_data
|
21
|
+
answer.save if answer.data_changed?
|
22
|
+
end
|
23
|
+
|
24
|
+
def save!
|
25
|
+
answer.data = json_answer_data
|
26
|
+
answer.save! if answer.data_changed?
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def answer
|
32
|
+
@answer ||= ProfileWizard::Answer.find_or_initialize_by(record: @record, name: @profile_attr)
|
33
|
+
end
|
34
|
+
|
35
|
+
def json_answer_data
|
36
|
+
data = {}
|
37
|
+
steps.each do |step_key, step|
|
38
|
+
data[step_key] = {}
|
39
|
+
step.questions.each do |question_key, question|
|
40
|
+
data[step_key][question_key] = question.answer
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
data
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ProfileWizard::Models
|
2
|
+
class Question
|
3
|
+
attr_accessor :answer
|
4
|
+
|
5
|
+
def initialize(question_key, question_schema, step)
|
6
|
+
@step = step
|
7
|
+
@meta_info = {}
|
8
|
+
@meta_info[:title] = question_schema[:title] || ActiveSupport::Inflector.humanize(question_key).titleize
|
9
|
+
@meta_info[:required] = question_schema[:required].nil? ? step.required? : question_schema[:required]
|
10
|
+
end
|
11
|
+
|
12
|
+
def title
|
13
|
+
@meta_info[:title]
|
14
|
+
end
|
15
|
+
|
16
|
+
def required?
|
17
|
+
@meta_info[:required]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ProfileWizard::Models
|
2
|
+
class Step
|
3
|
+
attr_accessor :questions,
|
4
|
+
:profile_wizard_step_title,
|
5
|
+
:profile_wizard_step_required
|
6
|
+
|
7
|
+
def initialize(step_key, step_schema)
|
8
|
+
@questions = {}
|
9
|
+
@meta_info = {}
|
10
|
+
@meta_info[:title] = step_schema[:title] || ActiveSupport::Inflector.humanize(step_key).titleize
|
11
|
+
@meta_info[:required] = step_schema[:required] || false
|
12
|
+
step_ref = self
|
13
|
+
step_schema[:questions].each do |question_key, question_schema|
|
14
|
+
self.class.class_eval do
|
15
|
+
define_method(question_key) do
|
16
|
+
@questions[question_key] ||= ProfileWizard::Models::Question.new(question_key, question_schema, step_ref)
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method("#{question_key}=") do |val|
|
20
|
+
@questions[question_key].answer = val
|
21
|
+
end
|
22
|
+
end
|
23
|
+
send(question_key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# We are making an assumption that there won't be a question with the key `:title`
|
28
|
+
def title
|
29
|
+
@meta_info[:title]
|
30
|
+
end
|
31
|
+
|
32
|
+
def required?
|
33
|
+
@meta_info[:required]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: profile_wizard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BV Satyaram
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-07 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: 5.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.2
|
27
|
+
description: ProfileWizard is a rails engine that lets you easily plug profile completion
|
28
|
+
wizard into your app, not worrying much about adding required profile fields to
|
29
|
+
your schema.
|
30
|
+
email:
|
31
|
+
- bvsatyaram@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- app/assets/config/profile_wizard_manifest.js
|
40
|
+
- app/assets/javascripts/profile_wizard/application.js
|
41
|
+
- app/assets/stylesheets/profile_wizard/application.css
|
42
|
+
- app/controllers/profile_wizard/application_controller.rb
|
43
|
+
- app/helpers/profile_wizard/application_helper.rb
|
44
|
+
- app/jobs/profile_wizard/application_job.rb
|
45
|
+
- app/mailers/profile_wizard/application_mailer.rb
|
46
|
+
- app/models/profile_wizard/answer.rb
|
47
|
+
- app/models/profile_wizard/application_record.rb
|
48
|
+
- app/views/layouts/profile_wizard/application.html.erb
|
49
|
+
- config/routes.rb
|
50
|
+
- db/migrate/20190307200449_create_profile_wizard_answers.rb
|
51
|
+
- lib/profile_wizard.rb
|
52
|
+
- lib/profile_wizard/engine.rb
|
53
|
+
- lib/profile_wizard/models.rb
|
54
|
+
- lib/profile_wizard/models/profile.rb
|
55
|
+
- lib/profile_wizard/models/question.rb
|
56
|
+
- lib/profile_wizard/models/step.rb
|
57
|
+
- lib/profile_wizard/version.rb
|
58
|
+
- lib/tasks/profile_wizard_tasks.rake
|
59
|
+
homepage: https://www.codeastra.com
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.7.8
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Pluggable profile completion wizard
|
83
|
+
test_files: []
|