Class: LeveretAuth::Config::Builder

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

Overview

Default DiviseAuth configuration builder

Instance Method Summary collapse

Constructor Details

#initialize(config = Config.new, &block) ⇒ Builder

Returns a new instance of Builder.



59
60
61
62
# File 'lib/leveret_auth/config.rb', line 59

def initialize(config = Config.new, &block)
  @config = config
  instance_eval(&block)
end

Instance Method Details

#add_provider(name, **opts) ⇒ Object



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

def add_provider(name, **opts)
  opts = Utils.load_json_file(opts[:file_path]) if opts[:file_path]
  begin
    klass = Strategies.const_get("#{name.to_s.camelize}Strategy")
  rescue NameError
    raise LoadError, "Could not find matching strategy for #{name}."
  end
  @config.providers << name.downcase
  klass.configure(opts.compact)
end

#before_user_save(&block) ⇒ Object



75
76
77
# File 'lib/leveret_auth/config.rb', line 75

def before_user_save(&block)
  @config.instance_variable_set(:@before_user_save, block) if block_given?
end

#buildObject



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

def build
  validate
  @config
end

#devise_for(model_name) ⇒ Object



71
72
73
# File 'lib/leveret_auth/config.rb', line 71

def devise_for(model_name)
  @config.instance_variable_set(:@user_model_name, model_name)
end

#validateObject



69
# File 'lib/leveret_auth/config.rb', line 69

def validate; end