Module: Task::Task::ClassMethods

Defined in:
lib/task/task.rb

Instance Method Summary collapse

Instance Method Details

#build(options) ⇒ Object

Instantiate an instance of this Task subclass.

Parameters:

  • options (Hash)

    Options to instantiate this Task. :task_list and :id are required; other arguments will be passed as data to the task.

Options Hash (options):

  • :task_list (String)
  • :id (String)


63
64
65
66
67
# File 'lib/task/task.rb', line 63

def build(options)
  task_list = options.delete(:task_list)
  id = options.delete(:id) || SecureRandom.hex
  new(task_list: task_list, id: id, data: options)
end

#create(options) ⇒ Object

Instantiate an instance of this Task subclass and save it to the datastore.

Parameters:

  • options (Hash)

    Options to instantiate this Task. :task_list and :id are required; other arguments will be passed as data to the task.

Options Hash (options):

  • :task_list (String)
  • :id (String)


74
75
76
77
78
# File 'lib/task/task.rb', line 74

def create(options)
  task = build(options)
  task.save
  task
end

#data_attr_reader(attr_name) ⇒ Object

Defines an attr reader instance method for a field in the data hash.

Examples:

class MyTask
  include Task::Task
  data_attr_reader :my_data_field
end

Parameters:

  • attr_name (Symbol)

    The attr name of the data field which will be used.



89
90
91
# File 'lib/task/task.rb', line 89

def data_attr_reader(attr_name)
  define_method(attr_name) { data[attr_name] }
end