Class: Jinda::Generators::ConfigGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Jinda::Generators::ConfigGenerator
- Defined in:
- lib/generators/jinda/config_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backup_files ⇒ Object
- #finish ⇒ Object
- #gen_image_store ⇒ Object
- #setup_ckeditor ⇒ Object
- #setup_mongoid ⇒ Object
- #setup_omniauth ⇒ Object
Class Method Details
.source_root ⇒ Object
4 5 6 |
# File 'lib/generators/jinda/config_generator.rb', line 4 def self.source_root File.dirname(__FILE__) + "/templates" end |
Instance Method Details
#backup_files ⇒ Object
8 9 10 11 12 13 |
# File 'lib/generators/jinda/config_generator.rb', line 8 def backup_files st=" " # inside("config/initializers") {(File.file? "omniauth.rb") ? (FileUtils.mv "omniauth.rb", "omniauth.rb.bak") : (puts "new omniauth.rb created")} # inside("config/initializers") {(File.file? "mongoid.rb") ? (FileUtils.mv "mongoid.rb", "omniauth.rb.bak") : (puts "new mongoid.rb created")} (File.file? ".env") ? (FileUtils.mv ".env", ".env-bak") : (puts "backup .env") end |
#finish ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/generators/jinda/config_generator.rb', line 80 def finish puts " configured omniauth.\n" puts " configured setup_ckeditor.\n" puts " configured Mongoid.\n" puts "\n" puts " To set user/password as admin/secret run:\n" puts "-----------------------------------------\n" puts "rails jinda:seed\n" puts "-----------------------------------------\n" puts " To test with rspec run:" puts "-----------------------------------------\n" puts "rspec\n" puts "-----------------------------------------\n" puts " To config rspec run:" puts "rails g jinda:rspec\n" puts "run $chromediver for Capybara & Chrome\n" puts "-----------------------------------------\n" puts " To config minitest run:" puts "-----------------------------------------\n" puts "rails g jinda:minitest\n" puts "-----------------------------------------\n" puts " To login with facebook" puts "-----------------------------------------\n" puts "Please config. in .env or restore from .env-bak \n" puts "-----------------------------------------\n" end |
#gen_image_store ⇒ Object
15 16 17 18 19 20 |
# File 'lib/generators/jinda/config_generator.rb', line 15 def gen_image_store # FileUtils.cp "cloudinary.yml","config/cloudinary.yml" # FileUtils.cp "dot.env",".env" # FileUtils.cp "dot.rspec",".rspec" empty_directory "upload" # create upload directory just in case end |
#setup_ckeditor ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/jinda/config_generator.rb', line 49 def setup_ckeditor initializer "ckeditor.rb" do %q{# gem 'ckeditor', github: 'galetahub/ckeditor' Ckeditor.setup do |config| require 'ckeditor/orm/mongoid' end } end end |
#setup_mongoid ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/generators/jinda/config_generator.rb', line 60 def setup_mongoid generate "mongoid:config" inject_into_file 'config/mongoid.yml', :after => ' # raise_not_found_error: true' do "\n raise_not_found_error: false" end inject_into_file 'config/mongoid.yml', :after => ' # belongs_to_required_by_default: true' do "\n belongs_to_required_by_default: false" end inject_into_file 'config/mongoid.yml', :after => ' # app_name: MyApplicationName' do "\n\nproduction:" + "\n clients:" + "\n default:" + "\n uri: <%= ENV['MONGODB_URI'] %>" + "\n options:" + "\n raise_not_found_error: false" + "\n belongs_to_required_by_default: false\n" end end |
#setup_omniauth ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/jinda/config_generator.rb', line 22 def setup_omniauth # gem 'bcrypt-ruby', '~> 3.0.0' # gem 'omniauth-identity' initializer "omniauth.rb" do %q{ Rails.application.config.middleware.use OmniAuth::Builder do provider :identity, :fields => [:code, :email], :on_failed_registration=> lambda { |env| IdentitiesController.action(:new).call(env) } provider :facebook, ENV['FACEBOOK_API'], ENV['FACEBOOK_KEY'] provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'] end # https://stackoverflow.com/questions/11461084/handle-omniautherror-invalid-credentials-for-identity-login OmniAuth.config.on_failure = Proc.new { |env| OmniAuth::FailureEndpoint.new(env).redirect_to_failure } } end end |