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.



193
194
195
# File 'lib/chefspec/coverage.rb', line 193

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

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



191
192
193
# File 'lib/chefspec/coverage.rb', line 191

def resource
  @resource
end

Instance Method Details

#source_fileObject



210
211
212
213
214
215
216
# File 'lib/chefspec/coverage.rb', line 210

def source_file
  @source_file ||= if @resource.source_line
                     shortname(@resource.source_line.split(":").first)
                   else
                     "Unknown"
                   end
end

#source_lineObject



218
219
220
221
222
223
224
# File 'lib/chefspec/coverage.rb', line 218

def source_line
  @source_line ||= if @resource.source_line
                     @resource.source_line.split(":", 2).last.to_i
                   else
                     "Unknown"
                   end
end

#to_jsonObject



201
202
203
204
205
206
207
208
# File 'lib/chefspec/coverage.rb', line 201

def to_json
  {
    "source_file" => source_file,
    "source_line" => source_line,
    "touched" => touched?,
    "resource" => to_s,
  }.to_json
end

#to_sObject



197
198
199
# File 'lib/chefspec/coverage.rb', line 197

def to_s
  @resource.to_s
end

#touch!Object



226
227
228
# File 'lib/chefspec/coverage.rb', line 226

def touch!
  @touched = true
end

#touched?Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/chefspec/coverage.rb', line 230

def touched?
  !!@touched
end