Module: RailsBestPractices::Core::Check::Accessable

Included in:
Prepares::ControllerPrepare, Prepares::HelperPrepare, Prepares::ModelPrepare
Defined in:
lib/rails_best_practices/core/check.rb

Overview

Helper to parse the access control.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/rails_best_practices/core/check.rb', line 401

def self.included(base)
  base.class_eval do
    interesting_nodes :var_ref, :vcall, :class, :module

    # remember the current access control for methods.
    add_callback :start_var_ref do |node|
      if %w[public protected private].include? node.to_s
        @access_control = node.to_s
      end
    end

    # remember the current access control for methods.
    add_callback :start_vcall do |node|
      if %w[public protected private].include? node.to_s
        @access_control = node.to_s
      end
    end

    # set access control to "public" by default.
    add_callback :start_class do |_node|
      @access_control = 'public'
    end

    # set access control to "public" by default.
    add_callback :start_module do |_node|
      @access_control = 'public'
    end
  end

  # get the current acces control.
  def current_access_control
    @access_control
  end
end

Instance Method Details

#current_access_controlObject

get the current acces control.



431
432
433
# File 'lib/rails_best_practices/core/check.rb', line 431

def current_access_control
  @access_control
end