Class: OpenWFE::UuidWfidGenerator

Inherits:
Service
  • Object
show all
Defined in:
lib/openwfe/expool/wfidgen.rb

Overview

A wfid generator that uses any underlying “uuidgen” command it might find. By default, it favours “uuidgen -t”.

You can specifying a command by passing a :uuid_command param in the application context, or simply by overriding the generate() method.

Constant Summary collapse

COMMANDS =
[
    "uuidgen -t",
    "uuidgen"
]

Instance Attribute Summary

Attributes included from ServiceMixin

#service_name

Attributes included from Contextual

#application_context

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ServiceMixin

#service_init, #stop

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Constructor Details

#initialize(service_name, application_context) ⇒ UuidWfidGenerator

Returns a new instance of UuidWfidGenerator.



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/openwfe/expool/wfidgen.rb', line 302

def initialize (service_name, application_context)

    super

    @command = @application_context[:uuid_command] \
        if @application_context

    unless @command
        COMMANDS.each do |c|
            c = "#{c} 2> /dev/null"
            s = `#{c}`
            h = s[0, 8].hex
            if h > 0
                @command = c
                break
            end
        end
    end

    raise "no command found for generating an uuid found..." \
        unless @command

    linfo { "new() command that will be used : '#{@command}'" }
end

Class Method Details

.split_wfid(wfid) ⇒ Object

This method is called by OpenWFE::split_wfid() when it has detected a wfid that is a UUID.

Splits the first part of the uuid (will be used for the expression storage directory structure).



352
353
354
355
356
357
358
359
360
# File 'lib/openwfe/expool/wfidgen.rb', line 352

def self.split_wfid (wfid)

    s = wfid[0, 8]
    a = []
    4.times do |i|
        a << s[i*2, 2]
    end
    a
end

Instance Method Details

#generate(launchitem = nil) ⇒ Object

Generates a brand new UUID

The launchitem parameter is not used by this generator.



332
333
334
335
# File 'lib/openwfe/expool/wfidgen.rb', line 332

def generate (launchitem=nil)

    `#{@command}`.chomp
end

#split_wfid(wfid) ⇒ Object

Is a simple call to OpenWFE::split_wfid()



340
341
342
343
# File 'lib/openwfe/expool/wfidgen.rb', line 340

def split_wfid (wfid)

    OpenWFE.split_wfid(wfid)
end