class Statics::Model
Public Class Methods
[](key)
click to toggle source
@param key [Symbol] @raise [Statics::KeyNotFoundError] if key is not found. @return [Statics::Model]
# File lib/statics/model.rb, line 19 def [](key) new(file_contents.fetch(key.to_s) { raise KeyNotFoundError }.merge(key: key.to_sym)) end
all()
click to toggle source
@return [Statics::Collection]
# File lib/statics/model.rb, line 24 def all @all ||= Collection.new(records) end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/statics/model.rb, line 28 def method_missing(method, *args, &block) if Collection.instance_methods.include?(method) all.public_send(method, *args, &block) else super end end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/statics/model.rb, line 36 def respond_to_missing?(method, include_private = false) Collection.instance_methods(false).include?(method) || super end
Private Class Methods
file_contents()
click to toggle source
@return [Hash]
# File lib/statics/model.rb, line 43 def file_contents @file_contents ||= YAML.load_file(path) end
path()
click to toggle source
@return [String]
# File lib/statics/model.rb, line 55 def path File.join(Statics.data_path, "#{filename}.yml") end
records()
click to toggle source
@return [Array<Statics::Model>]
# File lib/statics/model.rb, line 48 def records file_contents.map do |key, attributes| new(attributes.merge(key: key.to_sym)) end end