Sha256: 87ccdc61e11b7e32a8fd228020632a1ddc93fc32699b230279c2b6ee06d7b71e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module ActsAsCleo
  module ActsMethods
    def acts_as_cleo(opts = {})
      extend ClassMethods
      extend CommonMethods

      #Instance Methods Correctly Included
      include InstanceMethods

      before_create :set_cleo_id
      after_commit :sync_with_cleo
      after_destroy :remove_from_cleo

      cattr_accessor :cleo_config

      #set type to query against in Cleo
      #defaults to class name
      #ie "User" when acts_as_cleo is included in user.b
      self.cleo_config = {}
      opts[:except] ||= []
      opts[:except] += %w{id created_at updated_at}
      self.cleo_config[:type] = opts[:type] || self.ancestors.first.name

      self.cleo_config[:name] = opts[:name].blank? ? "name" : opts[:name]

      #specify what columns to add as part of the xml object
      #defaults to all columns in database
      self.cleo_config[:terms] = opts[:terms] || self.column_names
      self.cleo_config[:terms] = self.cleo_config[:terms] - opts[:except]

      #figure out what the score param is. execute the self.send(#{opts[:score].to_s}.count)
      opts[:score] ||= "id"
      self.cleo_config[:score] = opts[:score]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_cleo-0.0.3 lib/acts_methods.rb