Class: Knish::Reader
- Inherits:
-
Object
- Object
- Knish::Reader
- Defined in:
- lib/knish/reader.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #get_collections ⇒ Object
- #get_json ⇒ Object
- #get_markdown ⇒ Object
-
#initialize(config) ⇒ Reader
constructor
A new instance of Reader.
- #persisted? ⇒ Boolean
- #read_file(filename) ⇒ Object
- #template(key) ⇒ Object
Constructor Details
#initialize(config) ⇒ Reader
Returns a new instance of Reader.
5 6 7 |
# File 'lib/knish/reader.rb', line 5 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/knish/reader.rb', line 3 def config @config end |
Instance Method Details
#get_collections ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/knish/reader.rb', line 20 def get_collections config.collections.inject({}) do |hash, collection_name| collection = Collection.new(collection_name, config) collection.load hash[collection_name] = collection hash end end |
#get_json ⇒ Object
9 10 11 |
# File 'lib/knish/reader.rb', line 9 def get_json JSON.parse(read_file(config.data_filename) || '{}') end |
#get_markdown ⇒ Object
13 14 15 16 17 18 |
# File 'lib/knish/reader.rb', line 13 def get_markdown config.markdown_attributes.inject({}) do |hash, key| hash[key] = read_markdown(key) hash end end |
#persisted? ⇒ Boolean
33 34 35 |
# File 'lib/knish/reader.rb', line 33 def persisted? !!read_file(config.data_filename) end |
#read_file(filename) ⇒ Object
37 38 39 |
# File 'lib/knish/reader.rb', line 37 def read_file(filename) File.read("#{config.model_root}/#{filename}") rescue nil end |
#template(key) ⇒ Object
29 30 31 |
# File 'lib/knish/reader.rb', line 29 def template(key) "#{config.template_path}/#{key}" end |