Class: InvoiceCreator::ConfigReader
- Inherits:
-
Object
- Object
- InvoiceCreator::ConfigReader
- Includes:
- Singleton
- Defined in:
- lib/invoice_creator/config_reader.rb
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize ⇒ ConfigReader
constructor
A new instance of ConfigReader.
-
#method_missing(method, *args, &block) ⇒ Object
Hacky way to avoid having to define a method for each of the config properties.
- #respond_to_missing?(method_name, *args) ⇒ Boolean
- #settings ⇒ Object
Constructor Details
#initialize ⇒ ConfigReader
Returns a new instance of ConfigReader.
9 10 11 |
# File 'lib/invoice_creator/config_reader.rb', line 9 def initialize @yaml = YAML.load_file("config.yml") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Hacky way to avoid having to define a method for each of the config properties. Here just for fun and to make it easier to play around with the code. This causes undesireable downstream effects, i.e. calling ‘respond_to?(:anything)` would return true, which it’s fine in this codebase/project
25 26 27 |
# File 'lib/invoice_creator/config_reader.rb', line 25 def method_missing(method, *args, &block) settings.public_send(method) || data.public_send(method) || super end |
Instance Method Details
#data ⇒ Object
17 18 19 |
# File 'lib/invoice_creator/config_reader.rb', line 17 def data @data ||= OpenStruct.new(@yaml["data"]) end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
29 30 31 |
# File 'lib/invoice_creator/config_reader.rb', line 29 def respond_to_missing?(method_name, *args) true end |
#settings ⇒ Object
13 14 15 |
# File 'lib/invoice_creator/config_reader.rb', line 13 def settings @settings ||= OpenStruct.new(@yaml["settings"]) end |