gensearch 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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +10 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/modules.xml +8 -0
  6. data/.idea/turbolog.iml +42 -0
  7. data/.idea/vcs.xml +6 -0
  8. data/.idea/workspace.xml +307 -0
  9. data/.rspec +3 -0
  10. data/.travis.yml +21 -0
  11. data/CODE_OF_CONDUCT.md +74 -0
  12. data/Gemfile +6 -0
  13. data/Guardfile +12 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +81 -0
  16. data/Rakefile +21 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/gensearch.gemspec +35 -0
  20. data/lib/generators/gensearch/config_generator.rb +138 -0
  21. data/lib/generators/gensearch/install_generator.rb +67 -0
  22. data/lib/generators/gensearch/templates/.env +2 -0
  23. data/lib/generators/gensearch/templates/.gitignore +21 -0
  24. data/lib/generators/gensearch/templates/.rspec +2 -0
  25. data/lib/generators/gensearch/templates/app/controllers/Users/omniauth_callbacks_controller.rb +6 -0
  26. data/lib/generators/gensearch/templates/app/helpers/application_helper.rb +10 -0
  27. data/lib/generators/gensearch/templates/app/models/user.rb +12 -0
  28. data/lib/generators/gensearch/templates/application_controller_spec.rb +8 -0
  29. data/lib/generators/gensearch/templates/lib/string_calculator.rb +12 -0
  30. data/lib/generators/gensearch/templates/routes.rb +6 -0
  31. data/lib/generators/gensearch/templates/spec/controllers/welcomes_controller_spec.rb +86 -0
  32. data/lib/generators/gensearch/templates/spec/factories/users.rb +15 -0
  33. data/lib/generators/gensearch/templates/spec/factories/welcomes.rb +5 -0
  34. data/lib/generators/gensearch/templates/spec/helpers/welcomes_helper_spec.rb +23 -0
  35. data/lib/generators/gensearch/templates/spec/models/welcome_spec.rb +17 -0
  36. data/lib/generators/gensearch/templates/spec/rails_helper.rb +23 -0
  37. data/lib/generators/gensearch/templates/spec/requests/welcomes_spec.rb +16 -0
  38. data/lib/generators/gensearch/templates/spec/spec_helper.rb +96 -0
  39. data/lib/generators/gensearch/templates/spec/support/controller_helper.rb +12 -0
  40. data/lib/generators/gensearch/templates/spec/support/database_cleaner.rb +73 -0
  41. data/lib/generators/gensearch/templates/spec/support/devise.rb +8 -0
  42. data/lib/generators/gensearch/templates/spec/welcomes_controller_spec.rb +86 -0
  43. data/lib/gensearch.rb +6 -0
  44. data/lib/gensearch/helpers.rb +11 -0
  45. data/lib/gensearch/railtie.rb +18 -0
  46. data/lib/gensearch/version.rb +3 -0
  47. data/lib/tasks/gensearch.rake +28 -0
  48. metadata +258 -0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/kul1/gensearch.git" }
4
+
5
+ # Specify your gem's dependencies in gensearch.gemspec
6
+ gemspec
@@ -0,0 +1,12 @@
1
+
2
+ guard 'rspec' do
3
+ # watch /lib/ files
4
+ watch(%r{^lib/(.+).rb$}) do |m|
5
+ "spec/#{m[1]}_spec.rb"
6
+ end
7
+
8
+ # watch /spec/ files
9
+ watch(%r{^spec/(.+).rb$}) do |m|
10
+ "spec/#{m[1]}.rb"
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 P Kul
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.
@@ -0,0 +1,81 @@
1
+ # Gensearch
2
+
3
+ Gensearch is a gem to setup devise, omniauth and facebook authentication.
4
+
5
+ For the following configuration:
6
+
7
+ .Rails 5.1.4, 5.2.0.rc1
8
+ .Ruby 2.4.1, 2.5.0
9
+ .Devise
10
+ .Mongoid
11
+ .Omniauth_facebook
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'gensearch'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install gensearch
28
+
29
+ Once gensearch gem bundled, there are 3 steps to install.
30
+
31
+ Step 1/3 execute :
32
+
33
+ $ rails g gensearch:install
34
+
35
+ It will backup and will include several gems
36
+
37
+ Step 2/3 bundle install
38
+
39
+ $ bundle install
40
+
41
+
42
+ Step 3/3 execute :
43
+
44
+ $ rails g gensearch:config
45
+
46
+ It will run mongoid:config, devise install, devise Users and config omniauth and generate scaffold welcome as an example
47
+
48
+ Additional Setup For Facebook in .env
49
+ for example
50
+ FACEBOOK_API="xxxxxxxxxxxxxxxxx"
51
+ FACEBOOK_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxx"
52
+ ## Usage
53
+
54
+ 1. Create new rails app
55
+
56
+ $ rails new sample -B -O -T
57
+ 2. Follow Installation 3 steps above
58
+
59
+ Other command:
60
+
61
+ To remove devise line from config/routes by execute the following command
62
+
63
+ $ rake gensearch:clean
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kul1/gensearch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
78
+
79
+ ## Code of Conduct
80
+
81
+ Everyone interacting in the Gensearch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kul1/gensearch/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ #require "rake/testtask"
4
+ # Rake::TestTask.new(:test) do |t|
5
+ # t.libs << "test"
6
+ # t.libs << "lib"
7
+ # t.test_files = FileList["test/**/*_test.rb"]
8
+ # end
9
+
10
+ # task :default => :test
11
+
12
+
13
+ require 'rspec/core/rake_task'
14
+
15
+ # Default directory to look in is `/specs`
16
+ # Run with `rake spec`
17
+ RSpec::Core::RakeTask.new(:spec) do |task|
18
+ task.rspec_opts = ['--color', '--format', 'nested']
19
+ end
20
+
21
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gensearch"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "gensearch/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gensearch"
7
+ spec.version = Gensearch::VERSION
8
+ spec.authors = ["Prateep Kul"]
9
+ spec.email = ["1.0@kul.asia"]
10
+
11
+ spec.summary = %q{Create elasticsearch for Rails 5 }
12
+ spec.description = %q{Create elasticsearch for Rails 5}
13
+ spec.homepage = "https://github.com/kul1/gensearch"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "rspec", "~> 0"
26
+ spec.add_development_dependency "rspec-nc", "~> 0"
27
+ spec.add_development_dependency "guard", "~> 0"
28
+ spec.add_development_dependency "guard-rspec", "~> 0"
29
+ spec.add_development_dependency "pry", "~> 0"
30
+ spec.add_development_dependency "pry-remote", "~> 0"
31
+ spec.add_development_dependency "pry-nav", "~> 0"
32
+ spec.add_development_dependency "haml", ">= 5.0.4"
33
+ spec.add_development_dependency "haml-rails","~> 0"
34
+
35
+ end
@@ -0,0 +1,138 @@
1
+ require 'gensearch/helpers'
2
+ module Gensearch
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ def self.source_root
6
+ File.dirname(__FILE__) + "/templates"
7
+ end
8
+
9
+ def self.blue(mytext)
10
+ "\e[34m#{mytext}\e[0m".center(40)
11
+ end
12
+
13
+ desc "Config mongoid"
14
+ puts Color.blue(" .................run mongoid:config....................\n")
15
+
16
+ def config_mongoid
17
+ run "rails g mongoid:config"
18
+ end
19
+
20
+ def sethost_mongoid
21
+ puts Color.blue("..............change localhost to 127.0.0.1.............\n")
22
+ gsub_file 'config/mongoid.yml','localhost:27017','127.0.0.1:27017'
23
+ end
24
+
25
+ desc "Configure Devise"
26
+ def config_devise
27
+ puts Color.blue("..................rails g devise:install................\n")
28
+ run "rails generate devise:install"
29
+ puts Color.blue(" ..............Remove devise from routes.............\n")
30
+ gsub_file 'config/routes.rb',/devise_for.*\n/,''
31
+ puts Color.blue("....................rails g devise User.................\n")
32
+ run "rails generate devise User"
33
+ gsub_file 'config/initializers/devise.rb',/# config.secret_key/,'config.secret_key'
34
+ end
35
+
36
+ desc "Create Initial Sample Controller"
37
+ puts Color.blue(".............Create Welcome Initial Controller..........\n")
38
+ def create_welcome
39
+ run "rails g scaffold welcome greeting:text"
40
+ #copy_file "welcomes_controller_spec.rb","spec/controllers"
41
+ #copy_file "welcomes_spec.rb","spec/models"
42
+ end
43
+
44
+ def config_root
45
+ # set root to Welcome
46
+ puts Color.blue(".................config routes for user ................\n")
47
+ copy_file "routes.rb","config/routes.rb"
48
+ end
49
+
50
+ def dot_option
51
+ # set root to Welcome
52
+ puts Color.blue("......................config .rspec ....................\n")
53
+ copy_file ".rspec",".rspec"
54
+ copy_file ".env",".env"
55
+ copy_file ".gitignore",".gitignore" #protect .env
56
+ end
57
+
58
+ desc "authenticate_user"
59
+ def authenticate_user
60
+ puts Color.blue("..............Authenticate user in application..........\n")
61
+ inject_into_file 'app/controllers/application_controller.rb', :after => 'class ApplicationController < ActionController::Base' do
62
+ "\n before_action :authenticate_user!\n"
63
+ end
64
+ end
65
+
66
+ desc "Set up omniauth config"
67
+ def setup_omniauth
68
+ puts Color.blue("...............config devise for facebook...............\n")
69
+ inject_into_file 'config/initializers/devise.rb', :after => 'Devise.setup do |config|' do
70
+ "\n config.omniauth :facebook, ENV['FACEBOOK_API'], ENV['FACEBOOK_SECRET']\n"
71
+ end
72
+ puts Color.blue("..............config user model for facebook............\n")
73
+ inject_into_file 'app/models/user.rb', :after => 'include Mongoid::Document' do
74
+ "\n\n include Mongoid::Attributes::Dynamic" +
75
+ "\n devise :omniauthable, :omniauth_providers => [:facebook]" +
76
+ "\n def self.from_omniauth(auth)" +
77
+ "\n where(provider: auth.provider, uid: auth.uid).first_or_create do |user|" +
78
+ "\n user.email = auth.info.email" +
79
+ "\n user.password = Devise.friendly_token[0,20]" +
80
+ "\n end" +
81
+ "\n end\n"
82
+ end
83
+
84
+ puts Color.blue("...........Add field [provider] to user model...........\n")
85
+ inject_into_file 'app/models/user.rb', :after => ' field :encrypted_password, type: String, default: ""' do
86
+ "\n field :provider, type: String, default: \"\"\n"
87
+ "\n field :admin, type: Boolean, default: false \n"
88
+ end
89
+
90
+ end
91
+
92
+ desc "Add Log In/Log Out View in application.html.erb"
93
+ puts Color.blue("......Add Log In/Log Out View in application.html.......\n")
94
+
95
+ def log_in_out
96
+ inject_into_file 'app/views/layouts/application.html.erb', :after => '<body>' do
97
+ "\n "+
98
+ "\n <p class=\"notice\"><%= notice %></p>" +
99
+ "\n <p class=\"alert\"><%= alert %></p>" +
100
+ "\n <% if user_signed_in? %>" +
101
+ "\n <%= link_to \"Log Out\", destroy_user_session_path, method: :delete %>" +
102
+ "\n <% else %>" +
103
+ "\n <%= link_to(\"Log In\", new_user_session_path) %>" +
104
+ "\n <% end %>\n"
105
+ end
106
+ end
107
+
108
+ desc "Config default mail server in development and test"
109
+ puts Color.blue("......Add Log In/Log Out View in application.html.......\n")
110
+ def set_default_mailer
111
+ inject_into_file 'config/environments/development.rb', :after => 'ails.application.configure do' do
112
+ "\n ## config default mail server \n" +
113
+ " config.action_mailer.default_url_options = { host\: \"localhost\:3000\" }\n"
114
+ end
115
+ inject_into_file 'config/environments/test.rb', :after => 'ails.application.configure do' do
116
+ "\n ## config default mail server \n" +
117
+ " config.action_mailer.default_url_options = { host\: \"localhost\:3000\" }\n"
118
+ end
119
+ end
120
+
121
+ desc "Add user spec"
122
+ puts Color.blue("......................Add Spec Data.....................\n")
123
+ def add_spec
124
+ directory "spec"
125
+ # Added sample calculator test
126
+ directory "lib"
127
+ end
128
+
129
+ def finish
130
+ puts "\n"
131
+ puts Color.blue("________________________________________________________\n")
132
+ puts Color.blue(" Finished Step 3/3\n")
133
+ puts Color.blue("________________________________________________________\n")
134
+ end
135
+ end
136
+ end
137
+ end
138
+
@@ -0,0 +1,67 @@
1
+ require 'gensearch/helpers'
2
+ module Gensearch
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Install Gensearch component to existing Rails app "
6
+ def self.source_root
7
+ File.dirname(__FILE__) + "/templates"
8
+ end
9
+
10
+ def setup_gems
11
+ puts Color.blue(" ....................Insert Gems....................\n")
12
+ gem 'devise'
13
+ gem 'mongo', '~> 2.2'
14
+ gem 'bson', '~> 4.0'
15
+ gem 'mongoid', github: 'mongodb/mongoid'
16
+ gem 'nokogiri' # use for jinda/doc
17
+ gem 'haml', '~> 5.0', '>= 5.0.4'
18
+ gem 'haml-rails'
19
+ gem 'bcrypt'
20
+ gem 'omniauth-identity'
21
+ gem 'omniauth-facebook'
22
+ gem 'dotenv-rails'
23
+ gem_group :development, :test do
24
+ gem 'rspec'
25
+ gem 'rspec-rails'
26
+ gem 'better_errors'
27
+ gem 'binding_of_caller'
28
+ gem 'pry-byebug'
29
+ gem 'factory_bot_rails'
30
+ gem 'guard'
31
+ gem 'guard-rspec'
32
+ gem 'guard-minitest'
33
+ gem 'capybara'
34
+ gem 'rb-fsevent'
35
+ gem 'simplecov'
36
+ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master'
37
+ gem 'database_cleaner'
38
+ end
39
+ end
40
+
41
+ def backup_files
42
+ puts Color.blue(" ...................Backup Filess....................\n")
43
+ inside("app/controllers") {(File.file? "Users/omniauth_callbacks_controller.rb") ? (run "mv omniauth_callbacks_controller.rb omniauth_callbacks_controller.rb.bak") : (puts "No omniauth_callbacks_controller.rb")}
44
+ inside("config/initializers") {(File.file? "devise.rb") ? (run "mv devise.rb devise.rb.bak") : (puts "No devise.rb")}
45
+ inside("app/models") {(File.file? "user.rb") ? (run "mv user.rb user.rb.bak") : (puts "No user.rb")}
46
+ inside("app/helpers") {(File.file? "application_helper.rb") ? (run "mv application_helper.rb application_helper.rb.bak") : (puts "No application_helper.rb")}
47
+ inside("app/views/layouts") {(File.file? "application.html.erb") ? (run "cp application.html.erb application.html.erb.bak") : (puts "No application.html.erb")}
48
+ inside("config") {(File.file? "routes.rb") ? (run "cp routes.rb routes.rb.bak") : (puts "No routes.rb")}
49
+ directory "app"
50
+ end
51
+ def remove_devise
52
+ puts Color.blue(" ..............Remove devise from routes.............\n")
53
+ gsub_file 'config/routes.rb',/devise_for.*\n/,''
54
+ end
55
+
56
+ def finish
57
+ puts "\n"
58
+ puts Color.blue(" ....................Finish Step 1/3..................\n")
59
+ puts "Next: Please run the following command:\n"
60
+ puts Color.blue("......................................................\n")
61
+ puts "$ bundle install\n"
62
+ puts "$ rails generate gensearch:config\n"
63
+ puts Color.blue("......................................................\n")
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,2 @@
1
+ FACEBOOK_API="16x"
2
+ FACEBOOK_SECRET="32y"
@@ -0,0 +1,21 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*
12
+ /tmp/*
13
+ !/log/.keep
14
+ !/tmp/.keep
15
+
16
+ /node_modules
17
+ /yarn-error.log
18
+
19
+ .byebug_history
20
+ .env-my
21
+
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation