Sha256: 28fb075842dd8aa855d411a7b4b4940de39e8a6842fff589c1655071620301ab

Contents?: true

Size: 974 Bytes

Versions: 5

Compression:

Stored size: 974 Bytes

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
    def self.add_model_class(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

5 entries across 5 versions & 1 rubygems

Version Path
volt-0.9.3 lib/volt/models/root_models/root_models.rb
volt-0.9.3.pre6 lib/volt/models/root_models/root_models.rb
volt-0.9.3.pre5 lib/volt/models/root_models/root_models.rb
volt-0.9.3.pre4 lib/volt/models/root_models/root_models.rb
volt-0.9.3.pre3 lib/volt/models/root_models/root_models.rb