Class: LcpRuby::Authorization::ScopeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/authorization/scope_builder.rb

Defined Under Namespace

Classes: ScopeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope_config, user) ⇒ ScopeBuilder

Returns a new instance of ScopeBuilder.



8
9
10
11
# File 'lib/lcp_ruby/authorization/scope_builder.rb', line 8

def initialize(scope_config, user)
  @scope_config = scope_config.is_a?(Hash) ? scope_config.transform_keys(&:to_s) : {}
  @user = user
end

Instance Attribute Details

#scope_configObject (readonly)

Returns the value of attribute scope_config.



6
7
8
# File 'lib/lcp_ruby/authorization/scope_builder.rb', line 6

def scope_config
  @scope_config
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/lcp_ruby/authorization/scope_builder.rb', line 6

def user
  @user
end

Instance Method Details

#apply(base_relation) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lcp_ruby/authorization/scope_builder.rb', line 13

def apply(base_relation)
  case scope_config["type"]
  when "field_match"
    apply_field_match(base_relation)
  when "association"
    apply_association_scope(base_relation)
  when "where"
    apply_where(base_relation)
  when "custom"
    apply_custom(base_relation)
  when "inherits"
    apply_inherits(base_relation)
  when "union"
    apply_union(base_relation)
  else
    base_relation
  end
end