Class: UserTasks::UserTask

Inherits:
Object
  • Object
show all
Defined in:
lib/user_tasks.rb

Overview

A convenience wrapper for handling user task related metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ UserTask

Returns a new instance of UserTask.

Parameters:

  • data (Array)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/user_tasks.rb', line 52

def initialize(data)
  raise "Improperly defined user task #{data} in user_tasks.yml." if data.nil? || data[0].nil?
  attributes = data[1]
  @prefix = data[0]
  @name = attributes['name']
  @description = attributes['description']
  @related = attributes['related']
  @hub = (attributes['hub'] ? true : false)
  @status = attributes['status']
  @categories = attributes['categories']

 #route = Rails.application.routes.named_routes.get('update_serial_find_task')

 #@defaults = route.required_defaults
 #@defaults.merge!(verb: route.verb)
end

Instance Attribute Details

#categoriesArray

Returns:

  • (Array)


43
44
45
# File 'lib/user_tasks.rb', line 43

def categories
  @categories
end

#descriptionString?

Returns a full sentence or two describing to the user what this task does.

Returns:

  • (String, nil)

    a full sentence or two describing to the user what this task does.



31
32
33
# File 'lib/user_tasks.rb', line 31

def description
  @description
end

#hubBoolean

Returns true if this task should be linked to from the hub.

Returns:

  • (Boolean)

    true if this task should be linked to from the hub



39
40
41
# File 'lib/user_tasks.rb', line 39

def hub
  @hub
end

#nameString

Returns the name, or if not otherwise named, the prefix humanized.

Returns:

  • (String)

    the name, or if not otherwise named, the prefix humanized



23
24
25
# File 'lib/user_tasks.rb', line 23

def name
  @name
end

#prefixString

Returns the Rails route prefix for the task.

Returns:

  • (String)

    the Rails route prefix for the task



27
28
29
# File 'lib/user_tasks.rb', line 27

def prefix
  @prefix
end

Returns an array of Rails route prefixes that link to related tasks/functionality.

Returns:

  • (Array, nil)

    an array of Rails route prefixes that link to related tasks/functionality



35
36
37
# File 'lib/user_tasks.rb', line 35

def related
  @related
end

#statusString

Returns:

  • (String)


47
48
49
# File 'lib/user_tasks.rb', line 47

def status
  @status
end

Instance Method Details

#pathString

Returns the prefix with _path appended.

Returns:

  • (String)

    the prefix with _path appended



88
89
90
# File 'lib/user_tasks.rb', line 88

def path
  "#{prefix}_path"
end

#requires_params?Boolean

Returns whether the route requires more than :action, :controller.

Returns:

  • (Boolean)

    whether the route requires more than :action, :controller



100
101
102
# File 'lib/user_tasks.rb', line 100

def requires_params?
  Rails.application.routes.named_routes.get(@prefix).required_keys.sort != [:action, :controller]
end

#to_hHash

Returns:

  • (Hash)


105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/user_tasks.rb', line 105

def to_h
  return {
    url_name: url,
    path_name: path,
    name: name,
    status: status,
    categories: categories,
    description: description,
    related: related,
    prefix: prefix,
    hub: hub
  }
end

#urlString

Returns the prefix with _url appended.

Returns:

  • (String)

    the prefix with _url appended



94
95
96
# File 'lib/user_tasks.rb', line 94

def url
  "#{prefix}_url"
end