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.2.3 examples/extending.rb
kmayer-highrise-0.11.0 examples/extending.rb
kmayer-highrise-0.11.1 examples/extending.rb
kmayer-highrise-0.12.0 examples/extending.rb
kmayer-highrise-0.13.0 examples/extending.rb
kmayer-highrise-0.8.0 examples/extending.rb
kmayer-highrise-0.8.1 examples/extending.rb
kmayer-highrise-0.9.0 examples/extending.rb
kmayer-highrise-0.9.1 examples/extending.rb
kmayer-highrise-0.9.2 examples/extending.rb
kmayer-highrise-1.0.1 examples/extending.rb
highrise-3.2.1 examples/extending.rb
highrise-3.1.6 examples/extending.rb
highrise-3.1.5 examples/extending.rb
highrise-3.1.2 examples/extending.rb
highrise-3.1.1 examples/extending.rb
highrise-3.1.0 examples/extending.rb
highrise-3.1.0.pre examples/extending.rb
highrise-3.0.5 examples/extending.rb
highrise-3.0.4 examples/extending.rb