Class: RVGP::Application::Config
- Inherits:
-
Object
- Object
- RVGP::Application::Config
- Includes:
- Pta::AvailabilityHelper
- Defined in:
- lib/rvgp/application/config.rb
Overview
This class provides the app configuration options accessors and parsing logic.
Instance Attribute Summary collapse
-
#prices_path ⇒ Object
readonly
Returns the value of attribute prices_path.
-
#project_journal_path ⇒ Object
readonly
Returns the value of attribute project_journal_path.
Instance Method Summary collapse
-
#[](attr) ⇒ Object
Return the contents of the provided attr, from the project’s config/rvgp.yaml.
-
#build_path(relpath = nil) ⇒ String
Returns the full path, to a file or directory, in the project’s build/ directory.
-
#grid_ending_at ⇒ Date
Returns the ending date, for all grids that will be generated in this project.
-
#grid_starting_at ⇒ Date
Returns the starting date, for all grids that will be generated in this project.
-
#grid_years ⇒ Array<Integer>
The years, for which we will be building grids.
-
#initialize(project_path) ⇒ Config
constructor
Given the provided project path, this object will parse and store the config/rvgp.yaml, as well as provide default values for otherwise unspecified attributes in this file.
-
#key?(attr) ⇒ TrueClass, FalseClass
Returns a boolean indicating whether a value for the provided attr was specified in the project’s config/rvgp.yaml.
-
#project_path(relpath = nil) ⇒ String
Returns the full path, to a file or directory, in the project.
Methods included from Pta::AvailabilityHelper
Constructor Details
#initialize(project_path) ⇒ Config
Given the provided project path, this object will parse and store the config/rvgp.yaml, as well as provide default values for otherwise unspecified attributes in this file.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rvgp/application/config.rb', line 16 def initialize(project_path) @project_path = project_path @build_path = format('%s/build', project_path) config_path = project_path 'config/rvgp.yml' @yaml = RVGP::Utilities::Yaml.new config_path, project_path if File.exist? config_path RVGP::Pta.pta_adapter = @yaml[:pta_adapter].to_sym if @yaml.key? :pta_adapter @prices_path = @yaml.key?(:prices_path) ? @yaml[:prices_path] : project_path('journals/prices.db') if @yaml.key?(:project_journal_path) @project_journal_path = project_path @yaml[:project_journal_path] else journals_in_project_path = Dir.glob format('%s/*.journal', @project_path) if journals_in_project_path.length != 1 raise StandardError, format( 'Unable to automatically determine the project journal. Probably you want one of these ' \ 'files: %<files>s. Set the project_journal_path parameter in ' \ 'your config file, to the relative pathname, of the project journal.', files: journals_in_project_path.join(', ') ) end @project_journal_path = journals_in_project_path.first end # I'm not crazy about this default.. Mabe we should raise an error if # this value isn't set... @grid_starting_at = @yaml[:grid_starting_at] if @yaml.key? :grid_starting_at @grid_starting_at ||= default_grid_starting_at # NOTE: pta_adapter.newest_transaction_date.year works in lieu of Date.today, # but that query takes time. (and it requires that we've already # performed a build step at the time it's called) so, we use # Date.today instead. @grid_ending_at = @yaml[:grid_ending_at] if @yaml.key? :grid_ending_at @grid_ending_at ||= default_grid_ending_at end |
Instance Attribute Details
#prices_path ⇒ Object (readonly)
Returns the value of attribute prices_path.
10 11 12 |
# File 'lib/rvgp/application/config.rb', line 10 def prices_path @prices_path end |
#project_journal_path ⇒ Object (readonly)
Returns the value of attribute project_journal_path.
10 11 12 |
# File 'lib/rvgp/application/config.rb', line 10 def project_journal_path @project_journal_path end |
Instance Method Details
#[](attr) ⇒ Object
Return the contents of the provided attr, from the project’s config/rvgp.yaml
58 59 60 |
# File 'lib/rvgp/application/config.rb', line 58 def [](attr) @yaml[attr] end |
#build_path(relpath = nil) ⇒ String
Returns the full path, to a file or directory, in the project’s build/ directory. If no relpath was provided, this method returns the full path to the project build directory.
99 100 101 |
# File 'lib/rvgp/application/config.rb', line 99 def build_path(relpath = nil) relpath ? [@build_path, relpath].join('/') : @build_path end |
#grid_ending_at ⇒ Date
Returns the ending date, for all grids that will be generated in this project.
77 78 79 |
# File 'lib/rvgp/application/config.rb', line 77 def grid_ending_at call_or_return_date @grid_ending_at end |
#grid_starting_at ⇒ Date
Returns the starting date, for all grids that will be generated in this project.
71 72 73 |
# File 'lib/rvgp/application/config.rb', line 71 def grid_starting_at call_or_return_date @grid_starting_at end |
#grid_years ⇒ Array<Integer>
The years, for which we will be building grids
83 84 85 |
# File 'lib/rvgp/application/config.rb', line 83 def grid_years grid_starting_at.year.upto(grid_ending_at.year) end |
#key?(attr) ⇒ TrueClass, FalseClass
Returns a boolean indicating whether a value for the provided attr was specified in the project’s config/rvgp.yaml
65 66 67 |
# File 'lib/rvgp/application/config.rb', line 65 def key?(attr) @yaml.key? attr end |
#project_path(relpath = nil) ⇒ String
Returns the full path, to a file or directory, in the project. If no relpath was provided, this method returns the full path to the project directory.
91 92 93 |
# File 'lib/rvgp/application/config.rb', line 91 def project_path(relpath = nil) relpath ? [@project_path, relpath].join('/') : @project_path end |