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

- (UserTask) initialize(data)

attr_reader :defaults



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

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

- (Array) categories

Returns the iconizable categories this task applies to (see yaml)

Returns:

  • (Array)

    the iconizable categories this task applies to (see yaml)



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

def categories
  @categories
end

- (String?) description

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

- (Boolean) hub

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

- (String) name

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

- (String) prefix

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

- (String) status

Returns the development status of the task (see yaml)

Returns:

  • (String)

    the development status of the task (see yaml)



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

def status
  @status
end

Instance Method Details

- (String) path

Returns the prefix with _path appended

Returns:

  • (String)

    the prefix with _path appended



85
86
87
# File 'lib/user_tasks.rb', line 85

def path
  "#{prefix}_path"
end

- (Boolean) requires_params?

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

Returns:

  • (Boolean)

    whether the route requires more than :action, :controller



97
98
99
# File 'lib/user_tasks.rb', line 97

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

- (String) url

Returns the prefix with _url appended

Returns:

  • (String)

    the prefix with _url appended



91
92
93
# File 'lib/user_tasks.rb', line 91

def url
  "#{prefix}_url"
end