Class: Librarian::RSpec::Support::CliMacro::FileMatcher
- Inherits:
-
Object
- Object
- Librarian::RSpec::Support::CliMacro::FileMatcher
- Defined in:
- lib/librarian/rspec/support/cli_macro.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#content ⇒ Object
Returns the value of attribute content.
-
#rel_path ⇒ Object
Returns the value of attribute rel_path.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #actual_content ⇒ Object
- #full_path ⇒ Object
-
#initialize(rel_path, content, options = { }) ⇒ FileMatcher
constructor
A new instance of FileMatcher.
- #matches?(base_path) ⇒ Boolean
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, = { }) self.rel_path = rel_path self.content = content self.type = [:type] end |
Instance Attribute Details
#base_path ⇒ Object
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 |
#content ⇒ Object
Returns the value of attribute content.
27 28 29 |
# File 'lib/librarian/rspec/support/cli_macro.rb', line 27 def content @content end |
#rel_path ⇒ Object
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 |
#type ⇒ Object
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_content ⇒ Object
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_path ⇒ Object
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
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 |