Class: Tuersteher::ExtensionSpecification

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

Instance Method Summary collapse

Constructor Details

#initialize(method_name, negation, expected_value = nil) ⇒ ExtensionSpecification

Returns a new instance of ExtensionSpecification.



502
503
504
# File 'lib/tuersteher.rb', line 502

def initialize method_name, negation, expected_value=nil
  @method, @negation, @expected_value = method_name, negation, expected_value
end

Instance Method Details

#grant?(path_or_model, method, login_ctx) ⇒ Boolean

Returns:

  • (Boolean)


506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/tuersteher.rb', line 506

def grant? path_or_model, method, 
  rc = false
  if path_or_model.is_a?(String)
    # path-variante
    return false if .nil?
    unless .respond_to?(@method)
      Tuersteher::TLogger.logger.warn("#{to_s}.grant? => false why Login-Context have not method '#{@method}'!")
      return false
    end
    if @expected_value
      rc = .send(@method, @expected_value)
    else
      rc = .send(@method)
    end
  else
    # model-variante
    unless path_or_model.respond_to?(@method)
      m_msg = path_or_model.instance_of?(Class) ? "Class '#{path_or_model.name}'" : "Object '#{path_or_model.class}'"
      Tuersteher::TLogger.logger.warn("#{to_s}.grant? => false why #{m_msg} have not method '#{@method}'!")
      return false
    end
    if @expected_value
      rc = path_or_model.send(@method, , @expected_value)
    else
      rc = path_or_model.send(@method, )
    end
  end
  rc = !rc if @negation
  rc
end

#to_sObject



537
538
539
540
# File 'lib/tuersteher.rb', line 537

def to_s
  val_s = @expected_value.nil? ? nil :  ", #{@expected_value}"
  "#{@negation && 'not.'}extension(:#{@method}#{val_s})"
end