Sha256: 156337abbe48dd0a97e2bc20f76aea885013fe53390df76c49c17d8a8d8683eb

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

class ModelController  
  def self.model(val)
    @@default_model = val
  end
  
  # Sets the current model on this controller
  def model(val)
    if val.is_a?(Symbol) || val.is_a?(String)
      collections = [:page, :store, :params]
      if collections.include?(val.to_sym)
        @model = self.send(val)
      else
        raise "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
      end
    elsif model
      @model = model
    else
      raise "model can not be #{model.inspect}"
    end
  end
  
  def self.new(*args, &block)
    inst = self.allocate
    if @@default_model
      inst.model(@@default_model || :page)
    end
    
    inst.initialize(*args, &block)
    
    return inst
  end
  
  def page
    $page.page
  end

  def store
    $page.store
  end

  def flash
    $page.flash
  end

  def params
    $page.params 
  end

  def url
    $page.url 
  end
  
  def channel
    $page.channel
  end
  
  def tasks
    $page.tasks
  end
  
  def controller
    @controller ||= ReactiveValue.new(Model.new)
  end

  def method_missing(method_name, *args, &block)
    return @model.send(method_name, *args, &block)      
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
volt-0.5.18 lib/volt/controllers/model_controller.rb
volt-0.5.17 lib/volt/controllers/model_controller.rb
volt-0.5.16 lib/volt/controllers/model_controller.rb
volt-0.5.15 lib/volt/controllers/model_controller.rb
volt-0.5.14 lib/volt/controllers/model_controller.rb
volt-0.5.13 lib/volt/controllers/model_controller.rb
volt-0.5.12 lib/volt/controllers/model_controller.rb
volt-0.5.11 lib/volt/controllers/model_controller.rb
volt-0.5.10 lib/volt/controllers/model_controller.rb
volt-0.5.9 lib/volt/controllers/model_controller.rb
volt-0.5.8 lib/volt/controllers/model_controller.rb
volt-0.5.7 lib/volt/controllers/model_controller.rb
volt-0.5.6 lib/volt/controllers/model_controller.rb
volt-0.5.4 lib/volt/controllers/model_controller.rb
volt-0.5.3 lib/volt/controllers/model_controller.rb
volt-0.5.2 lib/volt/controllers/model_controller.rb