To edit pages or tickets please login with username/password: aaf/aaf

Ticket #73 (new enhancement)

Opened 2 years ago

Last modified 1 year ago

A patch allowing for dynamic fields

Reported by: ry@tinyclouds.org Assigned to: somebody
Priority: minor Milestone: later
Component: 0plugin Version: 2.0
Keywords: Cc:

Description

I've added an option to acts_as_ferret to allow for dynamic fields. The option is :dynamic_field and it's value should be a symbol which references an instance method. The named method should return a hash with (field, value) pairs (field should be a symbol).

Example:

  acts_as_ferret(
    :fields => [:title, :original_filename, :category], 
    :dynamic_fields => :metadata_fields
  )


  def metadata_fields
    fields = Hash.new
    metadata_responses.each do |r|
      name = r.metadata_name.name.to_sym
      value = r.value
      if fields[name].nil?
        fields[name] = value
      else
        fields[name] << " #{value}"
      end
    end
    fields
  end

It doesn't appear that the SVN is working, I've been using acts_as_ferret_trunk_20061012.tgz. Instead of giving a patch I'll just post the code in here since it's short.

Add these lines to instance_methods.rb in the to_doc function (line 120 in my version)

          # Load dynamic documentation if supplied
          if configuration[:dynamic_fields]
            dynamic_fields = send configuration[:dynamic_fields]
            dynamic_fields.each do |field, value|
              doc[field] = value
            end
          end

Attachments

dynamic_fields.diff (0.8 kB) - added by ry@tinyclouds.org on 12/24/06 17:58:53.

Change History

12/24/06 17:58:53 changed by ry@tinyclouds.org

  • attachment dynamic_fields.diff added.

01/11/07 12:24:51 changed by pipetka

  • priority changed from minor to trivial.
  • version set to 2.0.
  • type changed from defect to task.
  • milestone set to milestone3.

dbc2aa70ec2f Great work vvv_5_1 vvv_5_1 vvv_5_2 vvv_5_2 vvv_5_3 vvv_5_3 vvv_5_4 vvv_5_4 vvv_5_5 vvv_5_5

06/19/07 07:58:17 changed by root

  • milestone deleted.

Milestone milestone3 deleted

06/19/07 08:57:41 changed by jk

  • priority changed from trivial to minor.
  • type changed from task to enhancement.
  • milestone set to later.

To edit pages or tickets please login with username/password: aaf/aaf