Sha256: 09fc0dc5b27bb9f22621b13a69649fb58f7b6d2cf95f5d84d1f930cf47e75bf6

Contents?: true

Size: 739 Bytes

Versions: 37

Compression:

Stored size: 739 Bytes

Contents

#
# Example of extending a class when you need to synthesize an attribute.
#
# Adds Highrise::Person.{phone,fax,email} to the Person class inside your
# module
#

module MyModule
  include Highrise
  
  Highrise::Person.class_eval do
    class << self
      def lookup(id, list, item, location)
        module_eval <<-EOT
          def #{id}
            contact_data.#{list}.each do |i|
              return i.#{item}.strip if i.location == "#{location}"
            end
            ''
          end
        EOT
      end
    
      private :lookup
    end
  
    lookup(:phone, 'phone_numbers',   'number',  'Work')
    lookup(:fax,   'phone_numbers',   'number',  'Fax')
    lookup(:email, 'email_addresses', 'address', 'Work')
  end
end

Version data entries

37 entries across 37 versions & 5 rubygems

Version Path
highrise-3.0.3 examples/extending.rb
peterosullivan-highrise-3.0.7 examples/extending.rb
peterosullivan-highrise-3.0.6 examples/extending.rb
peterosullivan-highrise-3.0.5 examples/extending.rb
peterosullivan-highrise-3.0.4 examples/extending.rb
peterosullivan-highrise-3.0.3 examples/extending.rb
peterosullivan-highrise-3.0.2 examples/extending.rb
highrise-3.0.1 examples/extending.rb
highrise-3.0.0 examples/extending.rb
rogerio-augusto-highrise-2.0.4 examples/extending.rb
rogerio-augusto-highrise-2.0.3 examples/extending.rb
rogerio-augusto-highrise-2.0.2 examples/extending.rb
highrise-2.0.1 examples/extending.rb
highrise-2.0.0 examples/extending.rb
highrise-1.2.0 examples/extending.rb
soleone-highrise-0.13.3 examples/extending.rb
highrise-1.0.4 examples/extending.rb