Class: UserTasks::UserTask
- Inherits:
-
Object
- Object
- UserTasks::UserTask
- Defined in:
- lib/user_tasks.rb
Overview
A convenience wrapper for handling user task related metadata.
Instance Attribute Summary collapse
- #categories ⇒ Array
-
#description ⇒ String?
A full sentence or two describing to the user what this task does.
-
#hub ⇒ Boolean
True if this task should be linked to from the hub.
-
#name ⇒ String
The name, or if not otherwise named, the prefix humanized.
-
#prefix ⇒ String
The Rails route prefix for the task.
-
#related ⇒ Array?
An array of Rails route prefixes that link to related tasks/functionality.
- #status ⇒ String
Instance Method Summary collapse
-
#initialize(data) ⇒ UserTask
constructor
A new instance of UserTask.
-
#path ⇒ String
The prefix with _path appended.
-
#requires_params? ⇒ Boolean
Whether the route requires more than :action, :controller.
- #to_h ⇒ Hash
-
#url ⇒ String
The prefix with _url appended.
Constructor Details
#initialize(data) ⇒ UserTask
Returns a new instance of UserTask.
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
#categories ⇒ Array
43 44 45 |
# File 'lib/user_tasks.rb', line 43 def categories @categories end |
#description ⇒ String?
Returns 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 |
#hub ⇒ Boolean
Returns 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 |
#name ⇒ String
Returns the name, or if not otherwise named, the prefix humanized.
23 24 25 |
# File 'lib/user_tasks.rb', line 23 def name @name end |
#prefix ⇒ String
Returns the Rails route prefix for the task.
27 28 29 |
# File 'lib/user_tasks.rb', line 27 def prefix @prefix end |
#related ⇒ Array?
Returns an array of Rails route prefixes that link to related tasks/functionality.
35 36 37 |
# File 'lib/user_tasks.rb', line 35 def @related end |
#status ⇒ String
47 48 49 |
# File 'lib/user_tasks.rb', line 47 def status @status end |
Instance Method Details
#path ⇒ String
Returns 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.
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_h ⇒ 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: , prefix: prefix, hub: hub } end |
#url ⇒ String
Returns the prefix with _url appended.
94 95 96 |
# File 'lib/user_tasks.rb', line 94 def url "#{prefix}_url" end |