Module: Masks::Access::ClassMethods

Defined in:
app/models/concerns/masks/access.rb

Overview

Class methods for classes that include Masks::Access.

Instance Method Summary collapse

Instance Method Details

#access(name, **opts) ⇒ nil

Registers the class by the supplied name.

Any opts provided will be used as defaults for instances, in addition to the data supplied in the app’s configuration.

This can be called multiple times. If names are the same, opts will be deep merged together. Different names can be supplied as well.

Parameters:

  • name (String)
  • opts (Hash)

Returns:

  • (nil)


115
116
117
118
119
120
121
# File 'app/models/concerns/masks/access.rb', line 115

def access(name, **opts)
  @access_name = name

  Masks::Access.register(access_name, **opts.merge(cls: self))

  nil
end

#access_configString

Returns the configuration for the class.

This is a combination of data provided to access along with whatever is specifed in the configuration object for the access class.

Returns:

  • (String)


129
130
131
# File 'app/models/concerns/masks/access.rb', line 129

def access_config
  Masks.configuration.access(access_name)
end

#access_nameString

Returns the canonical access name for the class.

Returns:

  • (String)


99
100
101
# File 'app/models/concerns/masks/access.rb', line 99

def access_name
  @access_name
end

#build(request) ⇒ Masks::Access #build(controller) ⇒ Masks::Access #build(session) ⇒ Masks::Access #build(actor) ⇒ Masks::Access #build(**attrs) ⇒ Masks::Access

Builds a new access class, given a variety of arguments.

Overloads:

Returns:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/models/concerns/masks/access.rb', line 146

def build(arg1 = nil, **args)
  case arg1
  when ActionDispatch::Request
    new(session: Masks::Sessions::Request.new(session: arg1))
  when ActionController::Metal
    new(session: arg1.send(:masked_session))
  when Masks::Session
    new(session: arg1, **args)
  when Masks::Actor
    new(session: Masks::Sessions::Actor.new(arg1, **opts))
  when nil
    new(**opts)
  end
end