Class: Sexp

### Home Classes Methods

### In Files

- lib/rails_best_practices/core/visitable_sexp.rb

### Parent

Object

### Methods

- #accept
- #arguments
- #body
- #call
- #children
- #conditional_statement
- #false_node
- #grep_nodes
- #is_language_node?
- #message
- #message_name
- #node_type
- #recursive_children
- #subject
- #to_ruby
- #to_ruby_string
- #true_node
- #visitable_children

### Files

- LICENSE

### Class/Module Index

Quicksearch

- RailsBestPractices
- RailsBestPractices::Checks
- RailsBestPractices::Checks::AddModelVirtualAttributeCheck
- RailsBestPractices::Checks::AlwaysAddDbIndexCheck
- RailsBestPractices::Checks::Check
- RailsBestPractices::Checks::IsolateSeedDataCheck
- RailsBestPractices::Checks::KeepFindersOnTheirOwnModelCheck
- RailsBestPractices::Checks::LawOfDemeterCheck
- RailsBestPractices::Checks::ManyToManyCollectionCheck
- RailsBestPractices::Checks::MoveCodeIntoControllerCheck
- RailsBestPractices::Checks::MoveCodeIntoHelperCheck
- RailsBestPractices::Checks::MoveCodeIntoModelCheck
- RailsBestPractices::Checks::MoveFinderToNamedScopeCheck
- RailsBestPractices::Checks::MoveModelLogicIntoModelCheck
- RailsBestPractices::Checks::NeedlessDeepNestingCheck
- RailsBestPractices::Checks::NestedModelFormsCheck
- RailsBestPractices::Checks::NotUseDefaultRouteCheck
- RailsBestPractices::Checks::OveruseRouteCustomizationsCheck
- RailsBestPractices::Checks::ReplaceComplexCreationWithFactoryMethodCheck
- RailsBestPractices::Checks::ReplaceInstanceVariableWithLocalVariableCheck
- RailsBestPractices::Checks::UseBeforeFilterCheck
- RailsBestPractices::Checks::UseModelAssociationCheck
- RailsBestPractices::Checks::UseModelCallbackCheck
- RailsBestPractices::Checks::UseObserverCheck
- RailsBestPractices::Checks::UseScopeAccessCheck
- RailsBestPractices::Core
- RailsBestPractices::Core::CheckingVisitor
- RailsBestPractices::Core::Error
- RailsBestPractices::Core::Runner
- Enumerable
- NilClass
- Sexp
- String

No matching classes.

# Sexp

### Public Instance Methods

accept(visitor) click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 6
    def accept(visitor)
      visitor.visit(self)
    end

arguments() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 61
    def arguments
      if [:attrasgn, :call].include? node_type
        self[3]
      end
    end

body() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 97
    def body
      if :block == node_type
        self[1..-1]
      elsif :class == node_type
        self[3]
      elsif :defn == node_type
        self[3][1]
      elsif :defs == node_type
        self[4][1]
      end
    end

call() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 67
    def call
      if [:if, :arglist].include? node_type
        self[1]
      end
    end

children() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 14
    def children
      find_all { | sexp | Sexp === sexp }
    end

conditional_statement() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 73
    def conditional_statement
      if node_type == :if
        self[1]
      end
    end

false_node() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 85
    def false_node
      if :if == node_type
        self[3]
      end
    end

grep_nodes(options) click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 34
    def grep_nodes(options)
      return self if options.empty?
      node_type = options[:node_type]
      subject = options[:subject]
      message = options[:message]
      arguments = options[:arguments]
      nodes = []
      self.recursive_children do |child|
        if (!node_type or node_type == child.node_type) and (!subject or subject == child.subject) and (!message or message == child.message) and (!arguments or arguments == child.arguments)
          nodes << child
        end
      end
      nodes
    end

is_language_node?() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 18
    def is_language_node?
      first.class == Symbol
    end

message() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 55
    def message
      if [:attrasgn, :call, :defs].include? node_type
        self[2]
      end
    end

message_name() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 91
    def message_name
      if :defn == node_type
        self[1]
      end
    end

node_type() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 10
    def node_type
      first
    end

recursive_children(&handler) click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 27
    def recursive_children(&handler)
      visitable_children.each do |child|
        handler.call child
        child.recursive_children(&handler)
      end
    end

subject() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 49
    def subject
      if [:attrasgn, :call, :iasgn, :lasgn, :class].include? node_type
        self[1]
      end
    end

to_ruby() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 109
    def to_ruby
      Ruby2Ruby.new.process(self) unless self.empty?
    end

to_ruby_string() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 113
    def to_ruby_string
      return nil if self.empty?
      eval(Ruby2Ruby.new.process(self)).to_s
    end

true_node() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 79
    def true_node
      if :if == node_type
        self[2]
      end
    end

visitable_children() click to toggle source

    # File lib/rails_best_practices/core/visitable_sexp.rb, line 22
    def visitable_children
      parent = is_language_node? ? sexp_body : self
      parent.children
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.