Module: Chef::IndexQueue::Indexable

Included in:
ApiClient, CookbookVersion, DataBag, DataBagItem, Environment, 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.



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

def index_id
  @index_id
end

Class Method Details

.included(including_class) ⇒ Object



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

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

Instance Method Details

#add_to_index(metadata = {}) ⇒ Object



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

def add_to_index(={})
 Chef::Log.debug("Pushing item to index queue for addition: #{self.()}")
  = ()
 obj_id = ["id"]
 obj = {:action => :add, :payload => self.()}

 publish_object(obj_id, obj)
end

#delete_from_index(metadata = {}) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/chef/index_queue/indexable.rb', line 77

def delete_from_index(={})
  Chef::Log.debug("Pushing item to index queue for deletion: #{self.()}")
   = ()
  obj_id = ["id"]
  obj = {:action => :delete, :payload => self.()}

  publish_object(obj_id, obj)
end

#index_object_typeObject



46
47
48
# File 'lib/chef/index_queue/indexable.rb', line 46

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)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/chef/index_queue/indexable.rb', line 50

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
  ["enqueued_at"] ||= Time.now.utc.to_i

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