Class: StructureProcessor
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- StructureProcessor
- Defined in:
- lib/ruby_diff/structure_processor.rb
Overview
StructureProcessor is a SexpProcessor which will generate a logical model of the ruby code. It can be fooled by metaprogramming and method redefinition, but in most cases should be fairly accurate.
Instance Attribute Summary collapse
-
#code_objects ⇒ Object
Returns the value of attribute code_objects.
-
#meta_methods ⇒ Object
readonly
Returns the value of attribute meta_methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#root_objects ⇒ Object
Returns the value of attribute root_objects.
-
#scope_stack ⇒ Object
Returns the value of attribute scope_stack.
Instance Method Summary collapse
- #diff(other_processor) ⇒ Object
-
#initialize(name = '') ⇒ StructureProcessor
constructor
A new instance of StructureProcessor.
- #process_class(exp) ⇒ Object
- #process_defn(exp) ⇒ Object
- #process_defs(exp) ⇒ Object
- #process_fcall(exp) ⇒ Object
- #process_module(exp) ⇒ Object
- #process_sclass(exp) ⇒ Object
Constructor Details
#initialize(name = '') ⇒ StructureProcessor
Returns a new instance of StructureProcessor.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ruby_diff/structure_processor.rb', line 108 def initialize(name='') super() @name = name self.strict = false self.auto_shift_type = true @instance_scope = true @code_objects = {} @root_objects = {} @scope_stack = [] @meta_methods = { :attr_accessor => AccessorHandler.new("accessor"), :attr_writer => AccessorHandler.new("writer"), :attr_reader => AccessorHandler.new("reader") } end |
Instance Attribute Details
#code_objects ⇒ Object
Returns the value of attribute code_objects.
102 103 104 |
# File 'lib/ruby_diff/structure_processor.rb', line 102 def code_objects @code_objects end |
#meta_methods ⇒ Object (readonly)
Returns the value of attribute meta_methods.
106 107 108 |
# File 'lib/ruby_diff/structure_processor.rb', line 106 def @meta_methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
101 102 103 |
# File 'lib/ruby_diff/structure_processor.rb', line 101 def name @name end |
#root_objects ⇒ Object
Returns the value of attribute root_objects.
103 104 105 |
# File 'lib/ruby_diff/structure_processor.rb', line 103 def root_objects @root_objects end |
#scope_stack ⇒ Object
Returns the value of attribute scope_stack.
105 106 107 |
# File 'lib/ruby_diff/structure_processor.rb', line 105 def scope_stack @scope_stack end |
Instance Method Details
#diff(other_processor) ⇒ Object
188 189 190 |
# File 'lib/ruby_diff/structure_processor.rb', line 188 def diff(other_processor) method_diff = CodeComparison.new(self.root_objects, other_processor.root_objects).changes end |
#process_class(exp) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ruby_diff/structure_processor.rb', line 125 def process_class(exp) name = exp.shift super_class = exp.shift body = exp.shift name, temp_scope = process_colon2_constants(name) if name.is_a? Array record ClassCode.new(name, temp_scope || self.scope, body) do s(:class, name, process(super_class), process(body)) end end |
#process_defn(exp) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/ruby_diff/structure_processor.rb', line 148 def process_defn(exp) name = exp.shift body = process exp.shift record MethodCode.new(name, self.scope, @instance_scope, body) do s(:defn, name, body) end end |
#process_defs(exp) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/ruby_diff/structure_processor.rb', line 157 def process_defs(exp) exp_scope = process exp.shift name = exp.shift body = process exp.shift record MethodCode.new(name, self.scope, false, body) do s(:defs, exp_scope, name, body) end end |
#process_fcall(exp) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ruby_diff/structure_processor.rb', line 176 def process_fcall(exp) name = exp.shift args = process exp.shift if = @meta_methods[name] = .(args, self.scope) .each{|m| record(m)} end return s(:fcall, name, args) end |
#process_module(exp) ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ruby_diff/structure_processor.rb', line 137 def process_module(exp) name = exp.shift body = exp.shift name, temp_scope = process_colon2_constants(name) if name.is_a? Array record ModuleCode.new(name, temp_scope || self.scope, body) do s(:class, name, process(body)) end end |
#process_sclass(exp) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/ruby_diff/structure_processor.rb', line 167 def process_sclass(exp) @instance_scope = false exp_scope = process exp.shift body = process exp.shift @instance_scope = true s(:sclass, exp_scope, body) end |