class Knish::Reader

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/knish/reader.rb, line 5
def initialize(config)
  @config = config
end

Public Instance Methods

get_collections() click to toggle source
# 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() click to toggle source
# File lib/knish/reader.rb, line 9
def get_json
  JSON.parse(read_file(config.data_filename) || '{}')
end
get_markdown() click to toggle source
# 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?() click to toggle source
# File lib/knish/reader.rb, line 33
def persisted?
  !!read_file(config.data_filename)
end
read_file(filename) click to toggle source
# File lib/knish/reader.rb, line 37
def read_file(filename)
  File.read("#{config.model_root}/#{filename}") rescue nil
end
template(key) click to toggle source
# File lib/knish/reader.rb, line 29
def template(key)
  "#{config.template_path}/#{key}"
end

Private Instance Methods

read_markdown(key) click to toggle source
# File lib/knish/reader.rb, line 43
def read_markdown(key)
  read_file("_#{key}.md") || ""
end