Module: Cellect::Server::API::Helpers

Defined in:
lib/cellect/server/api/helpers.rb

Instance Method Summary collapse

Instance Method Details

#_param_to(param, conversion, default) ⇒ Object



59
60
61
62
# File 'lib/cellect/server/api/helpers.rb', line 59

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

#bad_requestObject



13
14
15
# File 'lib/cellect/server/api/helpers.rb', line 13

def bad_request
  error! 'Bad Request', 400
end

#four_oh_fourObject



9
10
11
# File 'lib/cellect/server/api/helpers.rb', line 9

def four_oh_four
  error! 'Not Found', 404
end

#param_to_float(param, default: nil) ⇒ Object



55
56
57
# File 'lib/cellect/server/api/helpers.rb', line 55

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

#param_to_int(param, default: nil) ⇒ Object



51
52
53
# File 'lib/cellect/server/api/helpers.rb', line 51

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

#selector_paramsObject



35
36
37
38
39
40
41
# File 'lib/cellect/server/api/helpers.rb', line 35

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

#update_paramsObject



43
44
45
46
47
48
49
# File 'lib/cellect/server/api/helpers.rb', line 43

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

#valid_group_id_update?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/cellect/server/api/helpers.rb', line 25

def valid_group_id_update?
  return true unless workflow.grouped?
  validate_param update_params, :group_id, expect: Fixnum
end

#valid_priority_update?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/cellect/server/api/helpers.rb', line 30

def valid_priority_update?
  return true unless workflow.prioritized?
  validate_param update_params, :priority, expect: Numeric
end

#valid_subject_id_update?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cellect/server/api/helpers.rb', line 21

def valid_subject_id_update?
  validate_param update_params, :subject_id, expect: Fixnum
end

#validate_param(hash, key, expect: nil) ⇒ Object



17
18
19
# File 'lib/cellect/server/api/helpers.rb', line 17

def validate_param(hash, key, expect: nil)
  hash[key] && hash[key].is_a?(expect)
end

#workflowObject



5
6
7
# File 'lib/cellect/server/api/helpers.rb', line 5

def workflow
  @workflow ||= Workflow[params[:workflow_id]]
end