Class: AnotherApi::Scope
- Inherits:
-
Data
- Object
- Data
- AnotherApi::Scope
- Defined in:
- lib/another_api/scope.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(group:, action: :all) ⇒ Scope
constructor
A new instance of Scope.
- #inspect ⇒ Object
- #matches?(other) ⇒ Boolean
- #qualified_name ⇒ Object
Constructor Details
#initialize(group:, action: :all) ⇒ Scope
Returns a new instance of Scope.
5 6 7 8 |
# File 'lib/another_api/scope.rb', line 5 def initialize(group:, action: :all) raise ArgumentError, "Invalid action: #{action}" unless SCOPE_ACTIONS.include?(action.to_sym) super(group: group.to_sym, action: action.to_sym) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action
4 5 6 |
# File 'lib/another_api/scope.rb', line 4 def action @action end |
#group ⇒ Object (readonly)
Returns the value of attribute group
4 5 6 |
# File 'lib/another_api/scope.rb', line 4 def group @group end |
Class Method Details
.parse(scope_str, prefix: AnotherApi.configuration.scope_prefix) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/another_api/scope.rb', line 10 def self.parse(scope_str, prefix: AnotherApi.configuration.scope_prefix) stripped = scope_str.to_s.delete_prefix(prefix) parts = stripped.split(".") raise ArgumentError, "Invalid scope string: #{scope_str}" if parts.size < 2 action = parts.pop group = parts.join(".") new(group: group.to_sym, action: action.to_sym) end |
Instance Method Details
#inspect ⇒ Object
27 28 29 |
# File 'lib/another_api/scope.rb', line 27 def inspect "#<AnotherApi::Scope #{group}.#{action}>" end |
#matches?(other) ⇒ Boolean
23 24 25 |
# File 'lib/another_api/scope.rb', line 23 def matches?(other) other.group == group && (action == :all || other.action == action) end |
#qualified_name ⇒ Object
19 20 21 |
# File 'lib/another_api/scope.rb', line 19 def qualified_name "#{AnotherApi.configuration.scope_prefix}#{group}.#{action}" end |