Class: Toni::PermissionMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/toni/permission_matcher.rb

Defined Under Namespace

Classes: NotMatcher, PermittedToMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, matcher, is_attr = false) ⇒ PermissionMatcher

Returns a new instance of PermissionMatcher.



6
7
8
9
10
# File 'lib/toni/permission_matcher.rb', line 6

def initialize(method_name, matcher, is_attr = false)
  @method_name  = method_name
  @matcher      = matcher
  @is_attr      = is_attr
end

Instance Attribute Details

#is_attrObject (readonly)

Returns the value of attribute is_attr.



4
5
6
# File 'lib/toni/permission_matcher.rb', line 4

def is_attr
  @is_attr
end

#matcherObject (readonly)

Returns the value of attribute matcher.



4
5
6
# File 'lib/toni/permission_matcher.rb', line 4

def matcher
  @matcher
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



4
5
6
# File 'lib/toni/permission_matcher.rb', line 4

def method_name
  @method_name
end

Instance Method Details

#matches?(object) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/toni/permission_matcher.rb', line 12

def matches?(object)
  unless object.respond_to?(method_name)
    raise Toni::NoMethodForMatcherError.new("#{method_name} is not defined for #{object.inspect}")
  end
  matcher.matches?(object.send(method_name))
end