Class: ChefSpec::Coverage::ResourceWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/chefspec/coverage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource = nil) ⇒ ResourceWrapper

Returns a new instance of ResourceWrapper.



132
133
134
# File 'lib/chefspec/coverage.rb', line 132

def initialize(resource = nil)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



130
131
132
# File 'lib/chefspec/coverage.rb', line 130

def resource
  @resource
end

Instance Method Details

#sourceObject



140
141
142
143
144
145
146
147
148
# File 'lib/chefspec/coverage.rb', line 140

def source
  return {} unless @resource.source_line
  file, line, *_ = @resource.source_line.split(':')

  {
    file: file,
    line: line.to_i,
  }
end

#to_hashObject



150
151
152
153
154
155
# File 'lib/chefspec/coverage.rb', line 150

def to_hash
  {
    source: source,
    touched: touched?,
  }
end

#to_sObject



136
137
138
# File 'lib/chefspec/coverage.rb', line 136

def to_s
  @resource.to_s
end

#touch!Object



157
158
159
# File 'lib/chefspec/coverage.rb', line 157

def touch!
  @touched = true
end

#touched?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/chefspec/coverage.rb', line 161

def touched?
  !!@touched
end