Class: Covered::Source
- Inherits:
-
Object
- Object
- Covered::Source
- Defined in:
- lib/covered/source.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#line_offset ⇒ Object
readonly
Returns the value of attribute line_offset.
-
#modified_time ⇒ Object
readonly
Returns the value of attribute modified_time.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#code! ⇒ Object
The actual code which is being covered.
- #code? ⇒ Boolean
-
#initialize(path, code: nil, line_offset: 1, modified_time: nil) ⇒ Source
constructor
A new instance of Source.
- #read(&block) ⇒ Object
- #serialize(packer) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, code: nil, line_offset: 1, modified_time: nil) ⇒ Source
Returns a new instance of Source.
17 18 19 20 21 22 |
# File 'lib/covered/source.rb', line 17 def initialize(path, code: nil, line_offset: 1, modified_time: nil) @path = path @code = code @line_offset = line_offset @modified_time = modified_time end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
25 26 27 |
# File 'lib/covered/source.rb', line 25 def code @code end |
#line_offset ⇒ Object (readonly)
Returns the value of attribute line_offset.
26 27 28 |
# File 'lib/covered/source.rb', line 26 def line_offset @line_offset end |
#modified_time ⇒ Object (readonly)
Returns the value of attribute modified_time.
27 28 29 |
# File 'lib/covered/source.rb', line 27 def modified_time @modified_time end |
#path ⇒ Object
Returns the value of attribute path.
24 25 26 |
# File 'lib/covered/source.rb', line 24 def path @path end |
Class Method Details
.deserialize(unpacker) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/covered/source.rb', line 57 def self.deserialize(unpacker) path = unpacker.read code = unpacker.read line_offset = unpacker.read modified_time = unpacker.read self.new(path, code: code, line_offset: line_offset, modified_time: modified_time) end |
.for(path, **options) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/covered/source.rb', line 8 def self.for(path, **) if File.exist?(path) # options[:code] ||= File.read(path) [:modified_time] ||= File.mtime(path) end self.new(path, **) end |
Instance Method Details
#code! ⇒ Object
The actual code which is being covered. If a template generates the source, this is the generated code, while the path refers to the template itself.
42 43 44 |
# File 'lib/covered/source.rb', line 42 def code! self.code || self.read end |
#code? ⇒ Boolean
46 47 48 |
# File 'lib/covered/source.rb', line 46 def code? !!self.code end |
#read(&block) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/covered/source.rb', line 33 def read(&block) if block_given? File.open(self.path, "r", &block) else File.read(self.path) end end |
#serialize(packer) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/covered/source.rb', line 50 def serialize(packer) packer.write(self.path) packer.write(self.code) packer.write(self.line_offset) packer.write(self.modified_time) end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/covered/source.rb', line 29 def to_s "\#<#{self.class} path=#{path}>" end |