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



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/rails_best_practices/core/check.rb', line 435

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.



465
466
467
# File 'lib/rails_best_practices/core/check.rb', line 465

def current_access_control
  @access_control
end