2009-06-17 19:14:05 -04:00
|
|
|
require "active_model"
|
|
|
|
|
2007-07-17 05:44:03 -04:00
|
|
|
class Customer < Struct.new(:name, :id)
|
2009-07-21 01:51:57 -04:00
|
|
|
extend ActiveModel::Naming
|
|
|
|
include ActiveModel::Conversion
|
2009-06-17 11:37:39 -04:00
|
|
|
|
2009-08-01 10:47:44 -04:00
|
|
|
undef_method :to_json
|
|
|
|
|
2009-08-13 04:27:41 -04:00
|
|
|
def to_xml(options={})
|
|
|
|
if options[:builder]
|
|
|
|
options[:builder].name name
|
|
|
|
else
|
|
|
|
"<name>#{name}</name>"
|
|
|
|
end
|
2009-08-01 10:47:44 -04:00
|
|
|
end
|
|
|
|
|
2009-08-13 04:27:41 -04:00
|
|
|
def to_js(options={})
|
|
|
|
"name: #{name.inspect}"
|
2009-08-01 10:47:44 -04:00
|
|
|
end
|
2010-02-16 17:26:29 -05:00
|
|
|
alias :to_text :to_js
|
2009-08-01 10:47:44 -04:00
|
|
|
|
|
|
|
def errors
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2010-02-21 05:09:21 -05:00
|
|
|
def persisted?
|
|
|
|
id.present?
|
2009-08-01 10:47:44 -04:00
|
|
|
end
|
2007-07-17 05:44:03 -04:00
|
|
|
end
|
2008-03-31 20:50:09 -04:00
|
|
|
|
2011-09-09 17:48:43 -04:00
|
|
|
class Post < Struct.new(:title, :author_name, :body, :secret, :persisted, :written_on, :cost)
|
2009-10-03 23:14:50 -04:00
|
|
|
extend ActiveModel::Naming
|
|
|
|
include ActiveModel::Conversion
|
2009-12-29 07:06:19 -05:00
|
|
|
extend ActiveModel::Translation
|
2009-10-03 23:14:50 -04:00
|
|
|
|
|
|
|
alias_method :secret?, :secret
|
2011-09-09 17:48:43 -04:00
|
|
|
alias_method :persisted?, :persisted
|
2009-10-03 23:14:50 -04:00
|
|
|
|
2010-10-04 22:32:49 -04:00
|
|
|
def initialize(*args)
|
|
|
|
super
|
|
|
|
@persisted = false
|
|
|
|
end
|
|
|
|
|
2009-10-03 23:14:50 -04:00
|
|
|
attr_accessor :author
|
|
|
|
def author_attributes=(attributes); end
|
|
|
|
|
2010-01-13 18:56:29 -05:00
|
|
|
attr_accessor :comments, :comment_ids
|
2009-10-03 23:14:50 -04:00
|
|
|
def comments_attributes=(attributes); end
|
|
|
|
|
|
|
|
attr_accessor :tags
|
|
|
|
def tags_attributes=(attributes); end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Comment
|
|
|
|
extend ActiveModel::Naming
|
|
|
|
include ActiveModel::Conversion
|
|
|
|
|
|
|
|
attr_reader :id
|
|
|
|
attr_reader :post_id
|
|
|
|
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
|
2010-02-20 21:05:28 -05:00
|
|
|
def to_key; id ? [id] : nil end
|
2009-10-03 23:14:50 -04:00
|
|
|
def save; @id = 1; @post_id = 1 end
|
2010-02-21 05:09:21 -05:00
|
|
|
def persisted?; @id.present? end
|
2010-07-24 11:43:50 -04:00
|
|
|
def to_param; @id.to_s; end
|
2009-10-03 23:14:50 -04:00
|
|
|
def name
|
|
|
|
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :relevances
|
|
|
|
def relevances_attributes=(attributes); end
|
|
|
|
|
2010-09-25 10:49:46 -04:00
|
|
|
attr_accessor :body
|
2009-10-03 23:14:50 -04:00
|
|
|
end
|