Sha256: 678a995dbe46a7bdcc37e7cda6a9d75f8ced0fc0cdd6e9dde26395fa7ee7a73c
Contents?: true
Size: 1.05 KB
Versions: 21
Compression:
Stored size: 1.05 KB
Contents
# When you get the root of a collection (.store, .page, etc...), it gives you # back a unique class depending on the collection. This allows you to add # things to the root easily. # # The name of the model will be {CollectionName}Root. All root model classes # inherit from BaseRootModel, which provides methods to access the model's # from the root. (store.items if you have an Item model for example) # Create a model that is above all of the root models. class BaseRootModel < Volt::Model end ROOT_MODEL_NAMES = [:Store, :Page, :Params, :Cookies, :LocalStore, :Flash] ROOT_MODEL_NAMES.each do |base_name| Object.const_set("#{base_name}Root", Class.new(BaseRootModel)) end module Volt class RootModels class_attribute :model_classes self.model_classes = [] def self.add_model_class(klass) self.model_classes << klass method_name = klass.to_s.underscore.pluralize # Create a getter for each model class off of root. BaseRootModel.send(:define_method, method_name) do get(method_name) end end end end
Version data entries
21 entries across 21 versions & 1 rubygems