Module: Archipelago::Disco::Publishable

Includes:
Camel
Included in:
Archipelago::Dump::Site, Tranny::Manager, Treasure::Chest
Defined in:
lib/archipelago/disco.rb

Overview

A module to simplify publishing of services.

If you include it you can use the publish! method at your convenience.

If you want to customize the publishing related behaviour you can call initialize_publishable with a Hash of options.

See Archipelago::Treasure::Chest or Archipelago::Tranny::Manager for examples.

It will store the service_id of this service in a directory beside this file (publishable.rb) named as the class you include into unless you define @persistence_provider before you call initialize_publishable.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from Camel

#jockey

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object

Also add the ClassMethods to base.



138
139
140
141
# File 'lib/archipelago/disco.rb', line 138

def self.append_features(base)
  super
  base.extend(ClassMethods)
end

Instance Method Details

#_dump(dummy_param) ⇒ Object

Dump a DRbObject refering to us.



155
156
157
# File 'lib/archipelago/disco.rb', line 155

def _dump(dummy_param)
  DRbObject.new(self)._dump(dummy_param)
end

#close!Object

Closes the persistence backend of this Publishable.



205
206
207
208
209
210
# File 'lib/archipelago/disco.rb', line 205

def close!
  unpublish!
  around_close do
    @persistence_provider.close!
  end
end

#publish!(options = {}) ⇒ Object

Create an Archipelago::Disco::Jockey for this instance using @jockey_options or optionally given :jockey_options.

Will publish this service using @service_description or optionally given :service_description.



166
167
168
169
170
171
# File 'lib/archipelago/disco.rb', line 166

def publish!(options = {})
  setup_jockey(options)
  around_publish do
    @jockey.publish(Archipelago::Disco::Record.new(@service_description.merge(options[:service_description] || {})))
  end
end

#service_idObject

Returns our semi-unique id so that we can be found again.



215
216
217
# File 'lib/archipelago/disco.rb', line 215

def service_id
  return @service_id ||= @metadata["service_id"]
end

#unpublish!Object

Stops the publishing of this Publishable.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/archipelago/disco.rb', line 187

def unpublish!
  if defined?(@jockey)
    if valid?
      around_unpublish do
        @valid = false
        if defined?(Archipelago::Disco::MC) && @jockey == Archipelago::Disco::MC
          @jockey.unpublish(self.service_id)
        else
          @jockey.stop!
        end
      end
    end
  end
end

#valid?Boolean

We are always valid if we are able to reply.

Returns:

  • (Boolean)


176
177
178
179
180
181
182
# File 'lib/archipelago/disco.rb', line 176

def valid?
  if defined?(@valid)
    @valid
  else
    @valid = true
  end
end