This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/concerns/auth.rb | |
module Concerns::Auth | |
extend ActiveSupport::Concern | |
class AccessDenied < RuntimeError; end | |
included do | |
helper_method :can? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) Для экземпляров класса Purchase задаём правила, | |
# по которым определяем доступные над ними | |
# действия. В нашем случае разрешаем всем :create | |
class Purchase | |
def allowed(object, subject) | |
rules = [] | |
return rules unless subject.kind_of?(Purchase) | |
rules << :create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PurchasesController | |
def create | |
purchase = Purchase.new :user => current_user | |
authorize! :create, purchase | |
# purchase create logic | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/layouts/application.html.slim | |
doctype html | |
html | |
head | |
title Hello, world! | |
body | |
= render 'cart' if can? :buy | |
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/web/application_controller.rb | |
class Web::ApplicationController < ApplicationController | |
include Concerns::Auth | |
rescue_from AccessDenied, :with => :access_denied_handler | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sidekiq/capistrano' | |
load 'config/deploy/extensions/sidekiq' # required to be after require 'sidekiq/capistrano' | |
set :sidekiq_role, :sidekiq | |
role :sidekiq, 'server1.com', 'server2.com' | |
# you may use default syntax – same number of processes at all hosts | |
# set :sidekiq_processes, 1 | |
# or use hash notation to specify host-dependent number of processes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task 'crlftolf', '', -> | |
execFile( | |
'find' | |
["#{__dirname}/www"] | |
(err, stdout, stderr) -> | |
file_list = stdout.split('\n') | |
for file in file_list | |
if file | |
stats = fs.lstatSync(file) | |
unless stats.isDirectory() |
NewerOlder