Sha256: 4a5e1d1ef12f6dc4aac42a7ec1045e125b12eb110f006a95cc35b2aee8ef3b98

Contents?: true

Size: 989 Bytes

Versions: 5

Compression:

Stored size: 989 Bytes

Contents

module Cellect
  module Server
    class API
      module Helpers
        def workflow
          @workflow ||= Workflow[params[:workflow_id]]
        end

        def selector_params
          {
            limit: param_to_int(:limit, default: 5),
            user_id: param_to_int(:user_id),
            group_id: param_to_int(:group_id)
          }
        end

        def update_params
          {
            subject_id: param_to_int(:subject_id),
            group_id: param_to_int(:group_id),
            priority: param_to_float(:priority)
          }
        end

        def param_to_int(param, default: nil)
          _param_to param, :to_i, default
        end

        def param_to_float(param, default: nil)
          _param_to param, :to_f, default
        end

        def _param_to(param, conversion, default)
          val = params[param] && params[param].send(conversion)
          params[param] && val && val > 0 ? val : default
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cellect-server-1.3.1 lib/cellect/server/api/helpers.rb
cellect-server-1.3.0 lib/cellect/server/api/helpers.rb
cellect-server-1.2.0 lib/cellect/server/api/helpers.rb
cellect-server-1.1.0 lib/cellect/server/api/helpers.rb
cellect-server-1.0.1 lib/cellect/server/api/helpers.rb