Skip to content

Commit

Permalink
Update the docs for Presenter, explaining why two methods are undocum…
Browse files Browse the repository at this point in the history
…ented and moving a third method into a protected section.
  • Loading branch information
mike-burns committed Sep 11, 2011
1 parent b770f30 commit 9e59334
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/liaison/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ def initialize(model_name, opts = {})
self.class.send(:attr_accessor,*@fields) unless @fields.nil? || @fields.empty?
end

def instance_validations
validates_with(@validator, :attributes => @fields) if @validator
end

# This only exists for ActiveModel::Naming
def self.model_name # :nodoc:
model_namer = Struct.new("ModelNamer", :name).new(@@model_name)
ActiveModel::Name.new(model_namer)
end

# This only exists for ActiveModel::Constructs
def persisted? # :nodoc:
false
end

# Set the params from the form using this.
#
# For example, if you have a presenter in the @sign_up_presenter variable,
# you can update the values in it using this method:
#
# @sign_up_presenter.with_params(params[:sign_up])
def with_params(params = {})
params.each {|k,v| self.send("#{k}=", v)}
Expand Down Expand Up @@ -72,8 +73,8 @@ def [](key)
to_hash[key]
end

# This is an instance of Enumerable, which means you can iterate over the
# keys and values as set by the form.
# Presenter objects are instances of Enumerable, which means you can iterate
# over the keys and values as set by the form.
#
# @sign_up_presenter.each {|k,v| puts "the form set #{k} to #{v}" }
def each(&block)
Expand All @@ -88,4 +89,8 @@ def to_hash
acc
end
end

def instance_validations
validates_with(@validator, :attributes => @fields) if @validator
end
end

0 comments on commit 9e59334

Please sign in to comment.