Class: AdLint::Source

Inherits:
Object
  • Object
show all
Extended by:
Pluggable
Defined in:
lib/adlint/source.rb

Overview

DESCRIPTION

Target source file.

Direct Known Subclasses

EmptySource, SystemHeader, UserHeader

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pluggable

def_plugin

Constructor Details

#initialize(fpath, fenc, included_at = Location.new) ⇒ Source

DESCRIPTION

Constructs a target source file.

PARAMETER

fpath

Pathname – Path name of the target source file.

content

String – Source content.



47
48
49
50
51
52
# File 'lib/adlint/source.rb', line 47

def initialize(fpath, fenc, included_at = Location.new)
  @fpath       = fpath
  @fenc        = fenc
  @included_at = included_at
  @content     = nil
end

Instance Attribute Details

#fpathObject (readonly)

VALUE

String – The path name of this source file.



62
63
64
# File 'lib/adlint/source.rb', line 62

def fpath
  @fpath
end

#included_atObject (readonly)

Returns the value of attribute included_at.



64
65
66
# File 'lib/adlint/source.rb', line 64

def included_at
  @included_at
end

Instance Method Details

#analysis_target?(traits) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/adlint/source.rb', line 74

def analysis_target?(traits)
  Location.new(@fpath).in_analysis_target?(traits)
end

#open(&block) ⇒ Object

DESCRIPTION

Opens the target source file.

PARAMETER

block

Proc – Yieldee block.



83
84
85
86
87
88
89
# File 'lib/adlint/source.rb', line 83

def open(&block)
  @content ||= read_content(@fpath)
  io = StringIO.new(@content)
  yield(io)
ensure
  io && io.close
end

#system_header?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/adlint/source.rb', line 70

def system_header?
  false
end

#to_sObject

DESCRIPTION

Converts this source content into string.

RETURN VALUE

String – Content of this source file.



96
97
98
# File 'lib/adlint/source.rb', line 96

def to_s
  @content ||= read_content(@fpath)
end

#user_header?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/adlint/source.rb', line 66

def user_header?
  false
end