class Noraneko::NConst
Attributes
extended_module_names[RW]
included_module_names[RW]
namespace[R]
path[R]
qualified_name[R]
registered_callbacks[RW]
Public Class Methods
new(qualified_name, path, line)
click to toggle source
# File lib/noraneko/nconst.rb, line 9 def initialize(qualified_name, path, line) @qualified_name = qualified_name @namespace = qualified_name.split('::') @path = path @line = line @methods = [] @included_module_names = [] @extended_module_names = [] @registered_callbacks = [] @called_views = [] @called_methods = [] @default_scope = :public @default_type = :instance end
Public Instance Methods
add_cmethod(name, line)
click to toggle source
# File lib/noraneko/nconst.rb, line 93 def add_cmethod(name, line) nmethod = NMethod.class_method(self, name, line) @methods << nmethod nmethod end
add_method(name, line)
click to toggle source
# File lib/noraneko/nconst.rb, line 87 def add_method(name, line) nmethod = NMethod.new(self, name, line, @default_scope, @default_type) @methods << nmethod nmethod end
all_instance_methods()
click to toggle source
# File lib/noraneko/nconst.rb, line 71 def all_instance_methods @methods.select { |method| method.instance_method? } end
all_methods()
click to toggle source
# File lib/noraneko/nconst.rb, line 67 def all_methods @methods end
all_private_methods()
click to toggle source
# File lib/noraneko/nconst.rb, line 75 def all_private_methods @methods.select { |method| method.in_private? } end
all_public_methods()
click to toggle source
# File lib/noraneko/nconst.rb, line 79 def all_public_methods @methods.select { |method| method.in_public? } end
all_used_modules()
click to toggle source
# File lib/noraneko/nconst.rb, line 83 def all_used_modules @included_module_names + @extended_module_names end
called?(target_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 114 def called?(target_name) @called_methods.any? { |name| name == target_name } end
called_view(view_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 99 def called_view(view_name) @called_views << view_name end
child_qualified_name(names)
click to toggle source
# File lib/noraneko/nconst.rb, line 36 def child_qualified_name(names) qualify(@namespace + names) end
controller?()
click to toggle source
# File lib/noraneko/nconst.rb, line 63 def controller? name.end_with?('Controller') end
find_method(method_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 49 def find_method(method_name) @methods.find do |method| method.name == method_name end end
loc()
click to toggle source
# File lib/noraneko/nconst.rb, line 24 def loc "#{@path}:#{@line}" end
make_method_private(name)
click to toggle source
# File lib/noraneko/nconst.rb, line 103 def make_method_private(name) target = @methods.find { |method| method.name == name } target.private! end
merge_singleton(other)
click to toggle source
# File lib/noraneko/nconst.rb, line 108 def merge_singleton(other) cm = other.all_instance_methods cm.each(&:class_method!) @methods += cm end
method_default_as_class!()
click to toggle source
# File lib/noraneko/nconst.rb, line 59 def method_default_as_class! @default_type = :class end
name()
click to toggle source
# File lib/noraneko/nconst.rb, line 28 def name @namespace.last || '' end
parent_name()
click to toggle source
# File lib/noraneko/nconst.rb, line 32 def parent_name qualify(@namespace[0..-2]) end
private!()
click to toggle source
# File lib/noraneko/nconst.rb, line 55 def private! @default_scope = :private end
register_csend(called_method_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 45 def register_csend(called_method_name) @called_methods << called_method_name end
register_send(method_name, called_method_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 40 def register_send(method_name, called_method_name) method = find_method(method_name) method.called_methods << called_method_name if method end
rel_path_from_controller()
click to toggle source
# File lib/noraneko/nconst.rb, line 134 def rel_path_from_controller @path .split('/controllers/').drop(1).join('') .split('_controller.rb').first + '/' end
used?(target_method)
click to toggle source
# File lib/noraneko/nconst.rb, line 118 def used?(target_method) return true if controller? && action_of_this?(target_method) return true if registered_callback?(target_method.name) all_methods.any? { |method| method.called?(target_method.name) } end
used_view?(target_view_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 124 def used_view?(target_view_name) explicit = @called_views.any? { |name| name == target_view_name } return true if explicit return false unless target_view_name.start_with?(rel_path_from_controller) tokens = target_view_name.split('/') return false if tokens.size < 2 method_name = tokens.last.to_sym all_public_methods.any? { |m| m.name == method_name } end
Private Instance Methods
action_of_this?(target_method)
click to toggle source
# File lib/noraneko/nconst.rb, line 142 def action_of_this?(target_method) target_method.in?(self) && target_method.in_public? end
qualify(names)
click to toggle source
# File lib/noraneko/nconst.rb, line 150 def qualify(names) names.join('::') end
registered_callback?(method_name)
click to toggle source
# File lib/noraneko/nconst.rb, line 146 def registered_callback?(method_name) @registered_callbacks.any? { |name| name == method_name } end