Sha256: 57218f067aed4590db893a15077f5de8a62ceea902e0529e23b954426d97e759

Contents?: true

Size: 1.29 KB

Versions: 67

Compression:

Stored size: 1.29 KB

Contents

# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/roles.rb

stage_two do
  say_wizard "recipe stage two"
  if (prefer :authorization, 'roles') || (prefer :authorization, 'pundit')
    if prefer :authentication, 'none'
      generate 'model User email:string'
      run 'bundle exec rake db:migrate'
    end
    generate 'migration AddRoleToUsers role:integer'
    role_boilerplate = "  enum role: [:user, :vip, :admin]\n  after_initialize :set_default_role, :if => :new_record?\n\n"
    role_boilerplate << "  def set_default_role\n    self.role ||= :user\n  end\n\n" if prefer :authentication, 'devise'
    if prefer :authentication, 'omniauth'
      role_boilerplate << <<-RUBY
  def set_default_role
    if User.count == 0
      self.role ||= :admin
    else
      self.role ||= :user
    end
  end
RUBY
    end
    inject_into_class 'app/models/user.rb', 'User', role_boilerplate
  end
  ### GIT ###
  git :add => '-A' if prefer :git, true
  git :commit => '-qm "rails_apps_composer: add roles to a User model"' if prefer :git, true
end

__END__

name: roles
description: "Add roles to a User model"
author: RailsApps

requires: [setup, gems, devise, omniauth]
run_after: [setup, gems, devise, omniauth]
category: mvc

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
rails_apps_composer-3.1.36 recipes/roles.rb
rails_apps_composer-3.1.35 recipes/roles.rb
rails_apps_composer-3.1.34 recipes/roles.rb
rails_apps_composer-3.1.33 recipes/roles.rb
rails_apps_composer-3.1.31 recipes/roles.rb
rails_apps_composer-3.1.30 recipes/roles.rb
rails_apps_composer-3.1.29 recipes/roles.rb
rails_apps_composer-3.1.28 recipes/roles.rb
rails_apps_composer-3.1.27 recipes/roles.rb
rails_apps_composer-3.1.25 recipes/roles.rb
rails_apps_composer-3.1.24 recipes/roles.rb
rails_apps_composer-3.1.23 recipes/roles.rb
rails_apps_composer-3.1.22 recipes/roles.rb
rails_apps_composer-3.1.21 recipes/roles.rb
rails_apps_composer-3.1.20 recipes/roles.rb
rails_apps_composer-3.1.19 recipes/roles.rb
rails_apps_composer-3.1.18 recipes/roles.rb
rails_apps_composer-3.1.17 recipes/roles.rb
rails_apps_composer-3.1.16 recipes/roles.rb
rails_apps_composer-3.1.15 recipes/roles.rb