Class: Librarian::RSpec::Support::CliMacro::FileMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/rspec/support/cli_macro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rel_path, content, options = { }) ⇒ FileMatcher

Returns a new instance of FileMatcher.



28
29
30
31
32
# File 'lib/librarian/rspec/support/cli_macro.rb', line 28

def initialize(rel_path, content, options = { })
  self.rel_path = rel_path
  self.content = content
  self.type = options[:type]
end

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



27
28
29
# File 'lib/librarian/rspec/support/cli_macro.rb', line 27

def base_path
  @base_path
end

#contentObject

Returns the value of attribute content.



27
28
29
# File 'lib/librarian/rspec/support/cli_macro.rb', line 27

def content
  @content
end

#rel_pathObject

Returns the value of attribute rel_path.



27
28
29
# File 'lib/librarian/rspec/support/cli_macro.rb', line 27

def rel_path
  @rel_path
end

#typeObject

Returns the value of attribute type.



27
28
29
# File 'lib/librarian/rspec/support/cli_macro.rb', line 27

def type
  @type
end

Instance Method Details

#actual_contentObject



36
37
38
39
40
41
42
# File 'lib/librarian/rspec/support/cli_macro.rb', line 36

def actual_content
  @actual_content ||= begin
    s = full_path.read
    s = JSON.parse(s) if type == :json
    s
  end
end

#full_pathObject



33
34
35
# File 'lib/librarian/rspec/support/cli_macro.rb', line 33

def full_path
  @full_path ||= base_path + rel_path
end

#matches?(base_path) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/librarian/rspec/support/cli_macro.rb', line 43

def matches?(base_path)
  base_path = Pathname(base_path) unless Pathname === base_path
  self.base_path = base_path

  full_path.file? && (!content || actual_content == content)
end