Sha256: 3c9d1ff86d06219b4fc06dcc50363302568a4c2d1588e99d935197f6b580a84b

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

module Cellect
  module Server
    module Adapters
      class Default
        # Return a list of workflows to load in the form:
        #   [{
        #     'id' => 123,
        #     'name' => 'foo',
        #     'prioritized' => false,
        #     'pairwise' => false,
        #     'grouped' => false
        #   }, ...]
        def workflow_list(*names)
          raise NotImplementedError
        end

        # Load the data for a workflow, this method:
        #   Accepts a workflow
        #   Returns an array of hashes in the form:
        #   {
        #     'id' => 123,
        #     'priority' => 0.123,
        #     'group_id' => 456
        #   }
        def load_data_for(workflow_name)
          raise NotImplementedError
        end

        # Load seen ids for a user, this method:
        #   Accepts a workflow_name, and a user id
        #   Returns an array in the form:
        #   [1, 2, 3]
        def load_user(workflow_name, id)
          raise NotImplementedError
        end

        # Report adapter status as a Hash
        def status
          { }
        end

        def load_workflows(*names)
          workflow_list(*names).each{ |workflow_info| load_workflow workflow_info }
        end

        def load_workflow(args)
          info = if args.is_a?(Hash)
            args
          elsif args.is_a?(String)
            workflow_list.select{ |h| h['name'] == args }.first
          else
            raise ArgumentError
          end

          workflow_for info
        end

        def workflow_for(opts = { })
          workflow_klass = opts.fetch('grouped', false) ? GroupedWorkflow : Workflow
          workflow_klass[opts['name']] = opts
          workflow_klass[opts['name']].load_data
          workflow_klass[opts['name']]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cellect-server-3.0.2 lib/cellect/server/adapters/default.rb
cellect-server-3.0.1 lib/cellect/server/adapters/default.rb
cellect-server-3.0.0 lib/cellect/server/adapters/default.rb
cellect-server-2.1.1 lib/cellect/server/adapters/default.rb