Class: Snp::Data
- Inherits:
-
Object
- Object
- Snp::Data
- Defined in:
- lib/snp/data.rb
Overview
Snp::Data
This class is responsible for fetching the default data to be used when compiling a template. This defaults to the data available on a YAML file located in ‘SNP_PATH`, if available.
Example
# Given there is a jquery.yml file in `SNP_PATH`, then
data = Snp::Data.for('jquery')
# => { 'version' => '1.9', 'cdn' => true }
Class Method Summary collapse
-
.for(template) ⇒ Object
Public: fetches the default data for the given template and parses it.
Instance Method Summary collapse
-
#initialize(template, path = Path.new) ⇒ Data
constructor
Public: creates a new ‘Snp::Data` instance for the template given.
-
#to_hash ⇒ Object
Public: fetches the data file and parses it, if available.
Constructor Details
Class Method Details
.for(template) ⇒ Object
Public: fetches the default data for the given template and parses it.
template - the template name whose data is to be fetched.
Returns a hash with the data.
21 22 23 |
# File 'lib/snp/data.rb', line 21 def self.for(template) new(template).to_hash end |
Instance Method Details
#to_hash ⇒ Object
Public: fetches the data file and parses it, if available.
Returns a hash of the parsed data.
34 35 36 37 38 39 40 |
# File 'lib/snp/data.rb', line 34 def to_hash if absolute_path YAML.load_file(absolute_path) else {} end end |