class Object

Public Instance Methods

is_still_a_node(code) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 225
def is_still_a_node(code)
  if code.is_a?(Parser::AST::Node)
    true
  else
    false
  end
end
look_for_auto_gen_methods(code, instance_variable,lvar_derived_from_ivar) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 93
def look_for_auto_gen_methods(code, instance_variable,lvar_derived_from_ivar)
  method_name = code.children[1]
  if method_name == $label
    method_argument_value = code.children[2].children[0]
    if method_argument_value.is_a?(Parser::AST::Node)
      method_argument_value = code.children[2].children[0].children[0].children[2].children[0]
      insert_outputs_on_array(method_argument_value, instance_variable)
    else
      insert_outputs_on_array(method_argument_value, instance_variable)
    end
  end
  if is_still_a_node(code.children[0])
    variable_type = code.children[0].type
    variable_calls_method = !code.children[1].nil?
    if variable_type == $lvar && variable_calls_method
      method_argument = code.children[0].children[0]
      if method_argument == lvar_derived_from_ivar
        insert_outputs_on_array(method_name, instance_variable)
      end
    end
  end
end
look_for_confirm_call(code) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 159
def look_for_confirm_call(code)
  has_aditional_call = !code.children[4].nil?
  if has_aditional_call
    link_to_type = code.children[4].type
    has_confirm_call = code.children[4].children[0].children[0].children[0]
    if link_to_type == $hash && has_confirm_call == $confirm
      link_to_redirect_name = code.children[2].children[0]
      link_to_argument_variable = code.children[3].children[0]
      insert_outputs_on_array("#{link_to_redirect_name}".downcase,Transform_into.var_into_controller(link_to_argument_variable))
      true
    end
  else
    false
  end
end
look_for_form_for_action(code, instance_variable) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 175
def look_for_form_for_action(code, instance_variable)
  if is_still_a_node(code)
    if code.type == $send
      loop_type = code.children[1]
      if loop_type == $form_for
        has_hash = !code.children[3].nil?
        if has_hash
          hash_implementation1 = code.children[3].children[1].nil?
          if hash_implementation1
            possible_hash = code.children[3].children[0].children[1].type
            if possible_hash == $hash
              loop_action = code.children[3].children[0].children[1].children[0].children[1].children[0]
            end
          else
            possible_hash = code.children[3].children[1].children[1].type
            if possible_hash == $hash
              loop_action = code.children[3].children[1].children[1].children[1].children[1].children[0]
            end
          end
          insert_outputs_on_array(loop_action, instance_variable)
        end
      end
    end
  end
end
look_for_form_tag_call(code, instance_variable) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 209
def look_for_form_tag_call(code, instance_variable)
  method_name = code.children[1]
  if method_name == $form_tag
    possible_hash = code.children[2].type
    if possible_hash == $hash
      method_argument = code.children[2].children[1].children[1].children[0]
      controller_called = code.children[2].children[0].children[1].children[0]
      insert_outputs_on_array(method_argument, controller_called)
    else
      method_argument = code.children[2].children[1]
      insert_outputs_on_array(method_argument, instance_variable)
    end

  end
end
look_for_instance_variable(code) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 137
def look_for_instance_variable(code)
  if $instance_variable == ""
    code.children.each do |code_children|
      if is_still_a_node(code_children)
        loop_type = code_children.children[1]
        if loop_type == $form_for && code_children.children[2].type == $ivar
          loop_variable_value = code_children.children[2].children[0]
          $instance_variable = loop_variable_value
        elsif  loop_type == $each
          loop_variable_value = code_children.children[0].children[0]
          if loop_variable_value.to_s[0] == '@'
              $instance_variable = loop_variable_value
          end
        end
        look_for_instance_variable(code_children)
      end
    end
  else
    $instance_variable = Transform_into.singular("#{$instance_variable}")
  end
end
look_for_loop_argument(code) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 116
def look_for_loop_argument(code)
  if $lvar_derived_from_ivar == ""
    code.children.each do |code_children|
      if is_still_a_node(code_children)
        if code_children.type == $block
          if code_children.children[0].type == $send
            loop_type = code_children.children[0].children[1]
            if loop_type == $each
              loop_argument_variable = code_children.children[1].children[0].children[0]
              $lvar_derived_from_ivar = loop_argument_variable
            end
          end
        end
        look_for_loop_argument(code_children)
      end
    end
  else
    $lvar_derived_from_ivar
  end
end
look_for_render_call(code, instance_variable) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 201
def look_for_render_call(code, instance_variable)
  method_name = code.children[1]
  if method_name == $render
    method_argument = code.children[2].children[0]
    insert_outputs_on_array(method_argument, instance_variable)
  end
end
look_for_submit_calls(code, instance_variable) click to toggle source
# File lib/ErbFileAnalyser/find_controller_calls.rb, line 78
def look_for_submit_calls(code, instance_variable)
  method_name = code.children[1]
  if method_name == $submit
    method_argument_type = code.children[2].type
    if method_argument_type == $str
      method_argument = code.children[2].children[0]
    else
      if method_argument_type == $send
        method_argument = code.children[3].children[0].children[1].children[0]
      end
    end
    insert_outputs_on_array("#{method_argument}".downcase,Transform_into.var_into_controller(instance_variable))
  end
end