Class: LoyalPassport::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/loyal_passport/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/loyal_passport/config.rb', line 40

def initialize
  ### Warden config ###############################
  #   Warden::Manager.before_failure do |env, opts|
  #     params = Rack::Request.new(env).params
  #     params[:action] = :unauthenticated
  #     params[:warden_failure] = opts
  #   end

  Warden::Manager.before_failure do |env, opts|
  #   params = Rack::Request.new(env).params
  #   params[:action] = :unauthenticated
  #   params[:warden_failure] = opts
  end
end

Instance Method Details

#authoritie_configsObject

权限定义



131
132
133
# File 'lib/loyal_passport/config.rb', line 131

def authoritie_configs
  @authoritie_configs ||= DEFAULT_AUTHORITY_CONFIGS
end

#authoritie_configs=(config = {}) ⇒ Object



124
125
126
127
128
# File 'lib/loyal_passport/config.rb', line 124

def authoritie_configs= config={}
  @authoritie_configs ||= DEFAULT_AUTHORITY_CONFIGS.deep_merge(
    config
  )
end

#cancan_abilitiesObject



120
121
122
# File 'lib/loyal_passport/config.rb', line 120

def cancan_abilities
  @cancan_abilities ||= DEFAULT_ABILITYS
end

#cancan_abilities=(abilities = []) ⇒ Object



114
115
116
117
118
# File 'lib/loyal_passport/config.rb', line 114

def cancan_abilities= abilities=[]
  @cancan_abilities ||= (
    DEFAULT_ABILITYS + abilities
  )
end

#dbObject



91
92
93
# File 'lib/loyal_passport/config.rb', line 91

def db
  @db_configs ||= DEFAULT_DB_CONFIG
end

#db=(options = {}) ⇒ Object



95
96
97
98
99
# File 'lib/loyal_passport/config.rb', line 95

def db= options={}
  @db_configs ||= DEFAULT_DB_CONFIG.merge(
    options
  )
end

#devise_install(&block) ⇒ Object

usage:

devise_install do |config|
  config.mailer_sender = ''
end


149
150
151
152
153
154
155
# File 'lib/loyal_passport/config.rb', line 149

def devise_install(&block)
  if block_given?
    Devise.setup do |config|
      block.call config
    end
  end
end

#logicsObject



65
66
67
# File 'lib/loyal_passport/config.rb', line 65

def logics
  @logics ||= DEFAULT_LOGICS
end

#logics=(logics = {}) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/loyal_passport/config.rb', line 69

def logics= logics={}
  @logics ||= (
    DEFAULT_LOGICS.merge(
      logics
    )
  )
end

#prepend_view_pathsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/loyal_passport/config.rb', line 77

def prepend_view_paths
  @prepend_view_paths ||= (
    self.white_hosts.inject({}) do |result, pair|
      host, config = pair

      if config[:view_paths]
        result[host] = ::LoyalPassport::ArrayUtil.init(config[:view_paths])
      end

      result
    end
  )
end

#request_routes_constraints?(request) ⇒ Boolean

判断请求是否可以路由到passport中来

Returns:

  • (Boolean)


110
111
112
# File 'lib/loyal_passport/config.rb', line 110

def request_routes_constraints?(request)
  request.subdomain == self.subdomain && self.white_hosts[request.host]
end

#resuce_cancan_access_denied_callObject



135
136
137
138
139
140
141
142
143
# File 'lib/loyal_passport/config.rb', line 135

def resuce_cancan_access_denied_call
  [
    :render,
    'loyal_passport/error/access_deny', {
      :layout => 'loyal_passport/application',
      :status => :forbidden
    }
  ]
end

#subdomainObject



105
106
107
# File 'lib/loyal_passport/config.rb', line 105

def subdomain
  @subdomain ||= DEFAULT_SUBDOMAIN
end

#subdomain=(subdomain = DEFAULT_SUBDOMAIN) ⇒ Object



101
102
103
# File 'lib/loyal_passport/config.rb', line 101

def subdomain= subdomain=DEFAULT_SUBDOMAIN
  @subdomain ||= subdomain
end

#white_hostsObject



61
62
63
# File 'lib/loyal_passport/config.rb', line 61

def white_hosts
  @white_hosts ||= DEFAULT_WHITE_HOSTS
end

#white_hosts=(hosts = DEFAULT_WHITE_HOSTS) ⇒ Object



55
56
57
58
59
# File 'lib/loyal_passport/config.rb', line 55

def white_hosts= hosts=DEFAULT_WHITE_HOSTS
  @white_hosts ||= (
    DEFAULT_WHITE_HOSTS.merge(hosts)
  )
end