Module: SuperAuth

Defined in:
lib/super_auth.rb,
lib/super_auth/railtie.rb,
lib/super_auth/version.rb

Defined Under Namespace

Modules: ActiveRecord, Nestable Classes: Authorization, Edge, Error, Group, Permission, Railtie, Resource, Role, User

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.current_userObject



70
71
72
# File 'lib/super_auth.rb', line 70

def self.current_user
  @current_user
end

.current_user=(user) ⇒ Object



66
67
68
# File 'lib/super_auth.rb', line 66

def self.current_user=(user)
  @current_user = user
end

.dbObject



78
79
80
# File 'lib/super_auth.rb', line 78

def self.db
  @db
end

.db=(db) ⇒ Object



74
75
76
# File 'lib/super_auth.rb', line 74

def self.db=(db)
  @db = db
end

.install_migrationsObject



44
45
46
47
48
49
50
# File 'lib/super_auth.rb', line 44

def self.install_migrations
  require "sequel"
  Sequel.extension :migration
  require "pathname"
  path = Pathname.new(__FILE__).parent.parent.join("db", "migrate")
  Sequel::Migrator.run(SuperAuth.db, path)
end

.set_dbObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/super_auth.rb', line 23

def self.set_db
  logger =
    if defined?(Rails) && ENV["SUPER_AUTH_LOG_LEVEL"] == "debug"
      Rails.logger
    elsif ENV["SUPER_AUTH_LOG_LEVEL"] == "debug"
      require "logger"
      logger = Logger.new(STDOUT)
    else
      nil
    end

  if !ENV['SUPER_AUTH_DATABASE_URL'].nil? && !ENV['SUPER_AUTH_DATABASE_URL'].empty?
    SuperAuth.db = Sequel.connect(ENV['SUPER_AUTH_DATABASE_URL'], logger: logger)
  else
    puts "ENV SUPER_AUTH_DATABASE_URL not set, using sqlite."
    SuperAuth.db = Sequel.sqlite(logger: logger, database: "./tmp/test.db")
    install_migrations
  end
  Sequel::Model.default_association_options = {:class_namespace=>'SuperAuth'}
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (SuperAuth)

    the object that the method was called on



19
20
21
# File 'lib/super_auth.rb', line 19

def self.setup
  yield self if block_given?
end

.uninstall_migrationsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/super_auth.rb', line 52

def self.uninstall_migrations
  require "sequel"
  set_db
  Sequel.extension :migration
  require "pathname"

  path = Pathname.new(__FILE__).parent.parent.join("db", "migrate")
  db = SuperAuth.db

  Sequel::Migrator.run(db, path, target: 0)
rescue => e
  raise Error, "Failed to uninstall migrations: #{e.message}"
end