Class: Stockboy::Provider Abstract
- Inherits:
-
Object
- Object
- Stockboy::Provider
- Extended by:
- ActiveModel::Naming, DSL
- Defined in:
- lib/stockboy/provider.rb
Overview
Provider objects handle the connection and capture of data from remote sources. This is an abstract superclass to help implement different providers.
Interface
A provider object must implement the following (private) methods:
- validate
-
Verify the parameters required for the data source are set to ensure a connection can be established.
- fetch_data
-
Populate the object’s @data with raw content from source. This will usually be a raw string, and should not be parsed at this stage. Depending on the implementation, this may involve any of:
-
Establishing a connection
-
Navigating to a directory
-
Listing available files matching the configuration
-
Picking the appropriate file
-
And finally, reading/downloading data
This should also capture the timestamp of the data resource into @data_time. This should be the actual created or updated time of the data file from the source.
-
Direct Known Subclasses
Stockboy::Providers::FTP, Stockboy::Providers::File, Stockboy::Providers::HTTP, Stockboy::Providers::IMAP, Stockboy::Providers::SOAP
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Raw input data from the source.
-
#data_time ⇒ Time
readonly
Timestamp of the received data.
- #errors ⇒ ActiveModel::Errors readonly
- #logger ⇒ Logger
Class Method Summary collapse
-
.logger ⇒ Logger
Default logger if none is provided to the instance.
Instance Method Summary collapse
-
#clear ⇒ Boolean
(also: #reset)
Reset received data.
-
#initialize(opts = {}) { ... } ⇒ Provider
constructor
Must be called by subclasses via
superto set up dependencies. - #inspect ⇒ String
-
#reload ⇒ String
Reload provided data.
-
#valid? ⇒ Boolean
Does the provider have what it needs for fetching data?.
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Raw input data from the source
81 82 83 84 85 |
# File 'lib/stockboy/provider.rb', line 81 def data return @data if @data fetch_data if validate_config? @data end |
#data_time ⇒ Time (readonly)
Timestamp of the received data
59 60 61 |
# File 'lib/stockboy/provider.rb', line 59 def data_time @data_time end |
#errors ⇒ ActiveModel::Errors (readonly)
53 54 55 |
# File 'lib/stockboy/provider.rb', line 53 def errors @errors end |
#logger ⇒ Logger
49 50 51 |
# File 'lib/stockboy/provider.rb', line 49 def logger @logger end |
Class Method Details
.logger ⇒ Logger
Default logger if none is provided to the instance
43 44 45 |
# File 'lib/stockboy/provider.rb', line 43 def self.logger Logger.new(STDERR) end |
Instance Method Details
#clear ⇒ Boolean Also known as: reset
Reset received data
91 92 93 94 95 96 97 |
# File 'lib/stockboy/provider.rb', line 91 def clear @data = nil @data_time = nil @data_size = nil @errors = ActiveModel::Errors.new(self) true end |
#inspect ⇒ String
63 64 65 |
# File 'lib/stockboy/provider.rb', line 63 def inspect "#<#{self.class}:#{self.object_id} data_size=#{@data_size or 'nil'} errors=#{@errors.}>" end |
#reload ⇒ String
Reload provided data
104 105 106 107 108 |
# File 'lib/stockboy/provider.rb', line 104 def reload clear fetch_data if validate_config? @data end |
#valid? ⇒ Boolean
Does the provider have what it needs for fetching data?
114 115 116 |
# File 'lib/stockboy/provider.rb', line 114 def valid? validate end |