Module: Chef::IndexQueue::Indexable

Included in:
ApiClient, CookbookVersion, DataBag, DataBagItem, Node, OpenIDRegistration, Role
Defined in:
lib/chef/index_queue/indexable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#index_idObject

Returns the value of attribute index_id.



41
42
43
# File 'lib/chef/index_queue/indexable.rb', line 41

def index_id
  @index_id
end

Class Method Details

.included(including_class) ⇒ Object



37
38
39
# File 'lib/chef/index_queue/indexable.rb', line 37

def self.included(including_class)
  including_class.send(:extend, ClassMethods)
end

Instance Method Details

#add_to_index(metadata = {}) ⇒ Object



64
65
66
67
# File 'lib/chef/index_queue/indexable.rb', line 64

def add_to_index(={})
  Chef::Log.debug("pushing item to index queue for addition: #{self.()}")
  AmqpClient.instance.send_action(:add, self.())
end

#delete_from_index(metadata = {}) ⇒ Object



69
70
71
72
# File 'lib/chef/index_queue/indexable.rb', line 69

def delete_from_index(={})
  Chef::Log.debug("pushing item to index queue for deletion: #{self.()}")
  AmqpClient.instance.send_action(:delete, self.())
end

#index_object_typeObject



43
44
45
# File 'lib/chef/index_queue/indexable.rb', line 43

def index_object_type
  self.class.index_object_type || Mixin::ConvertToClassName.snake_case_basename(self.class.name)
end

#with_indexer_metadata(indexer_metadata = {}) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/chef/index_queue/indexable.rb', line 47

def (={})
  # changing input param symbol keys to strings, as the keys in hash that goes to solr are expected to be strings [cb]
  # Ruby 1.9 hates you, cb [dan]
   = {}
  .each_key do |key|
    [key.to_s] = [key]
  end

  ["type"]     ||= self.index_object_type
  ["id"]       ||= self.index_id
  ["database"] ||= Chef::Config[:couchdb_database]
  ["item"]     ||= self.to_hash

  raise ArgumentError, "Type, Id, or Database missing in index operation: #{.inspect}" if (["id"].nil? or ["type"].nil?)
          
end