Class: Fixtury::Configuration
- Inherits:
-
Object
- Object
- Fixtury::Configuration
- Defined in:
- lib/fixtury/configuration.rb
Overview
Provides an interface for managing settings and dependencies related to fixture generation.
Instance Attribute Summary collapse
-
#dependency_files ⇒ Object
readonly
Returns the value of attribute dependency_files.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#fixture_files ⇒ Object
readonly
Returns the value of attribute fixture_files.
-
#locator_backend ⇒ Object
Returns the value of attribute locator_backend.
-
#reference_ttl ⇒ Object
Returns the value of attribute reference_ttl.
-
#strict_dependencies ⇒ Object
Returns the value of attribute strict_dependencies.
Instance Method Summary collapse
-
#add_dependency_path(*path_or_globs) ⇒ Object
(also: #add_dependency_paths)
Add a file or glob pattern to the list of dependency files.
-
#add_fixture_path(*path_or_globs) ⇒ Object
(also: #add_fixture_paths)
Add a file or glob pattern to the list of fixture files.
- #changes ⇒ Object
-
#dump_file ⇒ Object
Dump the current state of the dependency manager to the storage file.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #log_level ⇒ Object
- #log_level=(level) ⇒ Object
-
#reset ⇒ Object
Delete the storage file if it exists.
-
#stored_references ⇒ Hash
The references stored in the dependency file.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 |
# File 'lib/fixtury/configuration.rb', line 11 def initialize @fixture_files = Set.new @dependency_files = Set.new @locator_backend = :memory @strict_dependencies = true end |
Instance Attribute Details
#dependency_files ⇒ Object (readonly)
Returns the value of attribute dependency_files.
8 9 10 |
# File 'lib/fixtury/configuration.rb', line 8 def dependency_files @dependency_files end |
#filepath ⇒ Object
Returns the value of attribute filepath.
9 10 11 |
# File 'lib/fixtury/configuration.rb', line 9 def filepath @filepath end |
#fixture_files ⇒ Object (readonly)
Returns the value of attribute fixture_files.
8 9 10 |
# File 'lib/fixtury/configuration.rb', line 8 def fixture_files @fixture_files end |
#locator_backend ⇒ Object
Returns the value of attribute locator_backend.
8 9 10 |
# File 'lib/fixtury/configuration.rb', line 8 def locator_backend @locator_backend end |
#reference_ttl ⇒ Object
Returns the value of attribute reference_ttl.
9 10 11 |
# File 'lib/fixtury/configuration.rb', line 9 def reference_ttl @reference_ttl end |
#strict_dependencies ⇒ Object
Returns the value of attribute strict_dependencies.
9 10 11 |
# File 'lib/fixtury/configuration.rb', line 9 def strict_dependencies @strict_dependencies end |
Instance Method Details
#add_dependency_path(*path_or_globs) ⇒ Object Also known as: add_dependency_paths
Add a file or glob pattern to the list of dependency files.
51 52 53 |
# File 'lib/fixtury/configuration.rb', line 51 def add_dependency_path(*path_or_globs) @dependency_files = dependency_files | Dir[*path_or_globs] end |
#add_fixture_path(*path_or_globs) ⇒ Object Also known as: add_fixture_paths
Add a file or glob pattern to the list of fixture files.
43 44 45 |
# File 'lib/fixtury/configuration.rb', line 43 def add_fixture_path(*path_or_globs) @fixture_files = fixture_files | Dir[*path_or_globs] end |
#changes ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fixtury/configuration.rb', line 74 def changes return "new: #{filepath}" if stored_data.nil? stored_checksums = (stored_data[:dependencies] || {}) seen_filepaths = [] calculate_checksums do |filepath, checksum| # Early return if the checksums don't match return "change: #{filepath}" unless stored_checksums[filepath] == checksum seen_filepaths << filepath end # If we have a new file or a file has been removed, we need to report a change. new_files = seen_filepaths - stored_checksums.keys return "added: #{new_files.inspect}" if new_files.any? removed_files = stored_checksums.keys - seen_filepaths return "removed: #{removed_files.inspect}" if removed_files.any? nil end |
#dump_file ⇒ Object
Dump the current state of the dependency manager to the storage file.
67 68 69 70 71 72 |
# File 'lib/fixtury/configuration.rb', line 67 def dump_file return unless filepath FileUtils.mkdir_p(File.dirname(filepath)) File.binwrite(filepath, file_data.to_yaml) end |
#log_level ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/fixtury/configuration.rb', line 18 def log_level return @log_level if @log_level @log_level = ENV["FIXTURY_LOG_LEVEL"] @log_level ||= DEFAULT_LOG_LEVEL @log_level = @log_level.to_s.to_sym @log_level end |
#log_level=(level) ⇒ Object
27 28 29 |
# File 'lib/fixtury/configuration.rb', line 27 def log_level=(level) @log_level = level.to_s.to_sym end |
#reset ⇒ Object
Delete the storage file if it exists.
36 37 38 |
# File 'lib/fixtury/configuration.rb', line 36 def reset File.delete(filepath) if filepath && File.file?(filepath) end |
#stored_references ⇒ Hash
The references stored in the dependency file. When stores are initialized these will be used to bootstrap the references.
60 61 62 63 64 |
# File 'lib/fixtury/configuration.rb', line 60 def stored_references return {} if stored_data.nil? stored_data[:references] || {} end |