Sha256: b45fdf449f7cbdf4794b34f5c866b72cb55afd1d9167a5eb3abbd752da521f62
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
Contents
module SugarCRM; module AttributeMethods module ClassMethods # Returns a hash of the module fields from the module def attributes_from_module_fields fields = {} self._module.fields.keys.sort.each do |k| fields[k.to_s] = nil end fields end end # Generates get/set methods for keys in the attributes hash def define_attribute_methods return if attribute_methods_generated? @attributes.each_pair do |k,v| self.class.module_eval %Q? def #{k} read_attribute :#{k} end def #{k}=(value) write_attribute :#{k},value end ? end self.class.attribute_methods_generated = true end # Returns an <tt>#inspect</tt>-like string for the value of the # attribute +attr_name+. String attributes are elided after 50 # characters, and Date and Time attributes are returned in the # <tt>:db</tt> format. Other attributes return the value of # <tt>#inspect</tt> without modification. # # person = Person.create!(:name => "David Heinemeier Hansson " * 3) # # person.attribute_for_inspect(:name) # # => '"David Heinemeier Hansson David Heinemeier Hansson D..."' # # person.attribute_for_inspect(:created_at) # # => '"2009-01-12 04:48:57"' def attribute_for_inspect(attr_name) value = read_attribute(attr_name) if value.is_a?(String) && value.length > 50 "#{value[0..50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") else value.inspect end end protected # Wrapper around attributes hash def read_attribute(key) @attributes[key] end # Wrapper around attributes hash def write_attribute(key, value) @attributes[key] = value end end; end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sugarcrm-0.7.9 | lib/sugarcrm/attribute_methods.rb |
sugarcrm-0.7.8 | lib/sugarcrm/attribute_methods.rb |
sugarcrm-0.7.7 | lib/sugarcrm/attribute_methods.rb |