Top Level Namespace

Defined Under Namespace

Modules: Crosstie Classes: AuthenticationError, AuthorizationError, UsersController

Instance Method Summary collapse

Instance Method Details

#authenticate_any_role!(*roles) ⇒ Object



28
29
30
31
32
33
# File 'lib/crosstie/templates/authorization/application_controller.rb', line 28

def authenticate_any_role! *roles
  return unless user_signed_in?
  unless current_user.has_any_role? *roles
    raise AuthenticationError, "#{current_user.name} not authenticated as any of #{roles.join(", ")}"
  end
end

#authenticate_current_user!(user) ⇒ Object

Raises:



17
18
19
# File 'lib/crosstie/templates/authorization/application_controller.rb', line 17

def authenticate_current_user! user
  raise AuthorizationError unless current_user == user or current_user.system?
end

#authenticate_role!(role, resource = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/crosstie/templates/authorization/application_controller.rb', line 21

def authenticate_role! role, resource = nil
  return unless user_signed_in?
  unless current_user.has_role? role
    raise AuthenticationError, "#{current_user.name} not authenticated as a #{role} user"
  end
end

#configObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crosstie/base.rb', line 23

def config
  return @config if @config
  config_path = '/tmp/crosstie/config.yml'
  if File.exist? config_path
    @config = YAML.load(File.read(config_path))
    File.delete config_path
  else
    @config = {}
  end
  @config
end

#git_commit(message) ⇒ Object



3
4
5
6
# File 'lib/crosstie/base.rb', line 3

def git_commit message
  git add: '-A'
  git commit: "-a -m '#{message}'"
end

#perform(task) ⇒ Object



16
17
18
19
20
21
# File 'lib/crosstie/base.rb', line 16

def perform task
  eval File.read File.join root, "templates", "#{task}.rb"
rescue => e
  puts "error on performing #{task}"
  raise e
end

#read_template(*path) ⇒ Object



12
13
14
# File 'lib/crosstie/base.rb', line 12

def read_template *path
  File.read File.join root, "templates", *path
end

#rootObject



8
9
10
# File 'lib/crosstie/base.rb', line 8

def root
  @root ||= File.expand_path File.dirname __FILE__
end