Class: Joey::Photo
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
- #valid? ⇒ Boolean
-
#validate ⇒ Object
has_association :comments, “Comment”.
Methods inherited from Model
define_properties, find, get_all, has_association, hash_populating_accessor, hash_populating_association, #initialize, recognize?
Constructor Details
This class inherits a constructor from Joey::Model
Instance Method Details
#valid? ⇒ Boolean
35 36 37 38 39 |
# File 'lib/joey/photo.rb', line 35 def valid? self.validate puts self.errors.inspect unless self.errors.empty? self.errors.empty? end |
#validate ⇒ Object
has_association :comments, “Comment”
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/joey/photo.rb', line 13 def validate created_time.to_time rescue errors << { :message => 'created_time is not compatible' } updated_time.to_time rescue errors << { :message => 'updated_time is not compatible' } errors << { :message => 'id should not be nil' } if id.nil? errors << { :message => "name is neither string nor nil but is #{name.inspect}" } unless name.is_a?(String) || name.nil? errors << { :message => "source is neither string nor nil but is #{source.inspect}" } unless source.is_a?(String) || source.nil? errors << { :message => "height is neither integer nor nil but is #{height.inspect}" } unless height.is_a?(Integer) || height.nil? errors << { :message => "icon is neither string nor nil but is #{icon.inspect}" } unless icon.is_a?(String) || icon.nil? errors << { :message => "width is neither integer nor nil but is #{width.inspect}" } unless width.is_a?(Integer) || width.nil? errors << { :message => "from is not a Joey::User or Joey::Page and is #{from.inspect}" } unless from.is_a?(Joey::User) || from.is_a?(Joey::Page) errors << { :message => "comments is not an array nor nil and is #{comments.inspect}" } unless comments.is_a?(Array) || comments.nil? if comments.is_a?(Array) && !(comments.collect(&:class).uniq - [Joey::Comment]).empty? errors << { :message => 'comments is not an array of Joey::Comment' } end errors << { :message => "tags is not an array nor nil and is #{.inspect}" } unless .is_a?(Array) || .nil? if .is_a?(Array) && !(.collect(&:class).uniq - [Joey::Tag]).empty? errors << { :message => 'tags is not an array of Joey::Comment' } end end |