Class: AnotherApi::Scopes::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/another_api/scopes.rb

Instance Method Summary collapse

Constructor Details

#initialize(scopes_class) ⇒ DSL

Returns a new instance of DSL.



27
28
29
# File 'lib/another_api/scopes.rb', line 27

def initialize(scopes_class)
  @scopes_class = scopes_class
end

Instance Method Details

#scope(group, only: %i[list show create update delete])) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/another_api/scopes.rb', line 31

def scope(group, only: %i[list show create update delete])
  @scopes_class.registry[:"#{group}.all"] = Scope.new(group: group, action: :all)
  only.each do |action|
    @scopes_class.registry[:"#{group}.#{action}"] = Scope.new(group: group, action: action)
  end
rescue ArgumentError => e
  raise ArgumentError, "scope :#{group}#{e.message}"
end