Module: OmniAuth::Strategy::ClassMethods

Included in:
OmniAuth::Strategies::Developer
Defined in:
lib/omniauth/strategy/class_methods.rb,
sig/omniauth.rbs

Constant Summary collapse

DISPATCH_METHODS =

Returns:

  • (Array[Symbol])
%i[call! phase_call options_call? request_call? on_auth_path?].freeze

Instance Method Summary collapse

Instance Method Details

#allocate ⇒ Strategy

Defined by Class.

Returns:



355
# File 'sig/omniauth.rbs', line 355

def allocate: () -> Strategy

#ancestors ⇒ Array[Module]

Defined by Module, which every strategy class is.

Returns:

  • (Array[Module])


348
# File 'sig/omniauth.rbs', line 348

def ancestors: () -> Array[Module]

#args ⇒ Array[Symbol] #args(args) ⇒ nil

Sets (and retrieves) option key names for initializer arguments to be recorded as. This takes care of 90% of the use cases for overriding the initializer in OmniAuth Strategies.

Overloads:

  • #args ⇒ Array[Symbol]

    Returns:

    • (Array[Symbol])
  • #args(args) ⇒ nil

    Parameters:

    • args (Array[Symbol], Symbol)

    Returns:

    • (nil)


80
81
82
83
84
85
86
87
88
89
# File 'lib/omniauth/strategy/class_methods.rb', line 80

def args(args = nil)
  if args
    @args = args.is_a?(Array) ? args : [args]
    return
  end
  return @args if instance_variable_defined?(:@args)

  parent = superclass
  parent.is_a?(ClassMethods) ? parent.args : []
end

#class_eval ⇒ Object

Parameters:

  • code (String)
  • file (String)
  • line (Integer)

Returns:

  • (Object)


351
# File 'sig/omniauth.rbs', line 351

def class_eval: (String code, ?String file, ?Integer line) -> untyped

#compile_stack(ancestors, method, context) ⇒ Array[untyped]

Parameters:

  • ancestors (Array[Module])
  • method (Symbol)
  • context (Object)

Returns:

  • (Array[untyped])


107
108
109
110
111
112
113
114
115
# File 'lib/omniauth/strategy/class_methods.rb', line 107

def compile_stack(ancestors, method, context)
  stack = ancestors.inject([]) do |a, ancestor|
    # Only strategy classes define these blocks. Other ancestors may
    # respond to the same names (e.g. a monkeypatched Object#info).
    a << context.instance_eval(&ancestor.public_send(method)) if ancestor.is_a?(ClassMethods) && ancestor.public_send(method)
    a
  end
  stack.reverse
end

#configure(options = nil) {|Options| ... } ⇒ Object

This allows for more declarative subclassing of strategies by allowing default options to be set using a simple configure call.

Examples:

Using a yield to configure the default options.


class MyStrategy
  include OmniAuth::Strategy

  configure do |c|
    c.foo = 'bar'
  end
end

Using a hash to configure the default options.


class MyStrategy
  include OmniAuth::Strategy
  configure foo: 'bar'
end

Parameters:

  • options (Hash) (defaults to: nil) —

    If supplied, these will be the default options (deep-merged into the superclass's default options).

Yields:

  • (Options) —

    The options Mash that allows you to set your defaults as you'd like.

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (Object)


50
51
52
53
54
55
56
# File 'lib/omniauth/strategy/class_methods.rb', line 50

def configure(options = nil)
  if block_given?
    yield default_options
  else
    default_options.deep_merge!(options || {})
  end
end

#credentials ⇒ Proc #credentials ⇒ Proc?

Overloads:

  • #credentials ⇒ Proc

    Returns:

    • (Proc)
  • #credentials ⇒ Proc?

    Returns:

    • (Proc, nil)

Yields:

Yield Returns:

  • (void)


337
338
# File 'sig/omniauth.rbs', line 337

def credentials: () { () [self: Strategy] -> Hash[untyped, untyped]? } -> Proc
| () -> Proc?

#credentials_stack ⇒ Array[Hash[untyped, untyped]]

Parameters:

  • context (Object)

Returns:

  • (Array[Hash[untyped, untyped]])


343
# File 'sig/omniauth.rbs', line 343

def credentials_stack: (untyped context) -> Array[Hash[untyped, untyped]]

#default_dispatch? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

True when requests are dispatched by OmniAuth's own #call! and its phase checks, so #call can tell which ones would go to the app. They may live in Strategy or in a module it includes, like Paths. Methods patched directly onto Strategy count as its own.

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/omniauth/strategy/class_methods.rb', line 13

def default_dispatch?
  return @default_dispatch if instance_variable_defined?(:@default_dispatch)

  @default_dispatch = DISPATCH_METHODS.all? { |m| Strategy.ancestors.include?(instance_method(m).owner) }
end

#default_options ⇒ Options

Returns an inherited set of default options set at the class-level for each strategy.

Returns:



21
22
23
24
25
26
# File 'lib/omniauth/strategy/class_methods.rb', line 21

def default_options
  @default_options ||= begin
    parent = superclass
    Options.new((parent.default_options if parent.is_a?(ClassMethods)))
  end
end

#extra ⇒ Proc #extra ⇒ Proc?

Overloads:

  • #extra ⇒ Proc

    Returns:

    • (Proc)
  • #extra ⇒ Proc?

    Returns:

    • (Proc, nil)

Yields:

Yield Returns:

  • (void)


334
335
# File 'sig/omniauth.rbs', line 334

def extra: () { () [self: Strategy] -> Hash[untyped, untyped]? } -> Proc
| () -> Proc?

#extra_stack ⇒ Array[Hash[untyped, untyped]]

Parameters:

  • context (Object)

Returns:

  • (Array[Hash[untyped, untyped]])


342
# File 'sig/omniauth.rbs', line 342

def extra_stack: (untyped context) -> Array[Hash[untyped, untyped]]

#info ⇒ Proc #info ⇒ Proc?

Overloads:

  • #info ⇒ Proc

    Returns:

    • (Proc)
  • #info ⇒ Proc?

    Returns:

    • (Proc, nil)

Yields:

Yield Returns:

  • (void)


331
332
# File 'sig/omniauth.rbs', line 331

def info: () { () [self: Strategy] -> Hash[untyped, untyped]? } -> Proc
| () -> Proc?

#info_stack ⇒ Array[Hash[untyped, untyped]]

Parameters:

  • context (Object)

Returns:

  • (Array[Hash[untyped, untyped]])


341
# File 'sig/omniauth.rbs', line 341

def info_stack: (untyped context) -> Array[Hash[untyped, untyped]]

#instance_method ⇒ UnboundMethod

Parameters:

  • name (Symbol)

Returns:

  • (UnboundMethod)


352
# File 'sig/omniauth.rbs', line 352

def instance_method: (Symbol name) -> UnboundMethod

#name ⇒ String?

Returns:

  • (String, nil)


350
# File 'sig/omniauth.rbs', line 350

def name: () -> String?

#option(name, value = nil) ⇒ Object

Directly declare a default option for your class. This is a useful from a documentation perspective as it provides a simple line-by-line analysis of the kinds of options your strategy provides by default.

Examples:


class MyStrategy
  include OmniAuth::Strategy

  option :foo, 'bar'
  option
end

Parameters:

  • name (Symbol) —

    The key of the default option in your configuration hash.

  • value (Object) (defaults to: nil) —

    The value your object defaults to. Nil if not provided.

Returns:

  • (Object)


73
74
75
# File 'lib/omniauth/strategy/class_methods.rb', line 73

def option(name, value = nil)
  default_options[name] = value
end

#superclass ⇒ Class?

Returns:

  • (Class, nil)


349
# File 'sig/omniauth.rbs', line 349

def superclass: () -> Class?

#uid ⇒ Proc #uid ⇒ Proc?

The fetcher blocks run with the strategy instance as self.

Overloads:

  • #uid ⇒ Proc

    Returns:

    • (Proc)
  • #uid ⇒ Proc?

    Returns:

    • (Proc, nil)

Yields:

Yield Returns:

  • (void)


328
329
# File 'sig/omniauth.rbs', line 328

def uid: () { () [self: Strategy] -> untyped } -> Proc
| () -> Proc?

#uid_stack ⇒ Array[untyped]

Parameters:

  • context (Object)

Returns:

  • (Array[untyped])


340
# File 'sig/omniauth.rbs', line 340

def uid_stack: (untyped context) -> Array[untyped]