Skip to content

Commit

Permalink
ft: adds install files
Browse files Browse the repository at this point in the history
  • Loading branch information
wbotelhos committed Nov 10, 2020
1 parent ff1d621 commit 4590f5d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/generators/authorizy/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Authorizy
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)

desc 'Creates Initializer and Migration for Authorizy'

def create_initializer
copy_file 'config/initializers/authorizy.rb', 'config/initializers/authorizy.rb'
end

def create_migration
copy_file 'db/migrate/add_authorizy_on_users.rb', "db/migrate/#{timestamp(0)}_add_authorizy_on_users.rb"
end

private

def timestamp(seconds)
(Time.current + seconds.seconds).strftime('%Y%m%d%H%M%S')
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

Authorizy.configure do |config|
# Creates aliases to automatically allow permission for another action.
# https://github.com/wbotelhos/authorizy#aliases
# config.aliases = {}

# An interceptor to filter the request and decide if the request will be authorized
# https://github.com/wbotelhos/authorizy#cop
# config.cop = Authorizy::BaseCop

# The current user from we fetch the permissions
# https://github.com/wbotelhos/authorizy#current-user
# config.current_user = -> (context) { context.respond_to?(:current_user) ? context.current_user : nil }

# Inherited permissions from some other permission the user already has
# https://github.com/wbotelhos/authorizy#dependencies
# config.dependencies = {}

# URL to be redirect when user has no permission to access some resource
# https://github.com/wbotelhos/authorizy#dependencies
# config.redirect_url = -> (context) { context.respond_to?(:root_url) ? context.root_url : '/' }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddAuthorizyOnUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :authorizy, :jsonb, default: {}, null: false
end
end

0 comments on commit 4590f5d

Please sign in to comment.