Class: Inch::Codebase::Object

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/inch/codebase/object.rb

Overview

An object that holds a code_object as well as it's evaluation and exposes shortcut methods to the commonly asked members of both.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, code_object, object_lookup) ⇒ Object



30
31
32
33
34
# File 'lib/inch/codebase/object.rb', line 30

def initialize(language, code_object, object_lookup)
  @language = language
  @code_object = CodeObject::Proxy.for(language, code_object,
                                       object_lookup)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/inch/codebase/object.rb', line 47

def method_missing(name, *args, &block)
  if code_object.respond_to?(name)
    self.class.class_eval <<-RUBY
      def #{name}(*args, &block)
        code_object.#{name}(*args, &block)
      end
    RUBY
    code_object.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#code_objectObject (readonly)

Returns the value of attribute code_object



11
12
13
# File 'lib/inch/codebase/object.rb', line 11

def code_object
  @code_object
end

#gradeGrade



41
42
43
44
45
# File 'lib/inch/codebase/object.rb', line 41

def grade
  @grade ||= Evaluation.new_grade_lists.find do |range|
    range.scores.include?(score)
  end.grade
end

#languageString (readonly)



14
15
16
# File 'lib/inch/codebase/object.rb', line 14

def language
  @language
end

Instance Method Details

#evaluationObject



36
37
38
# File 'lib/inch/codebase/object.rb', line 36

def evaluation
  @evaluation ||= Evaluation::Proxy.for(@language, self)
end