Sha256: 7ed2609ccf15e19245a08f9c98b6f10f24ef9d3450119f2e84d5df9427b17573

Contents?: true

Size: 1.29 KB

Versions: 1

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, :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 "redmint_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

1 entries across 1 versions & 1 rubygems

Version Path
redmint_composer-2.3 recipes/roles.rb