Sha256: 2168d33a5f5adffc6b40bfa81f8e000c4f3b82cdfde234cf1365e26799a79b08

Contents?: true

Size: 836 Bytes

Versions: 4

Compression:

Stored size: 836 Bytes

Contents

module TaskManager
  class CurrentTaskFile < TaskFile
    def add(task)
      raise "You haven't finished the current task".colorize(:light_red) if current_node
      super
    end

    def current
      raise "You don't have any current task".colorize(:light_red) unless current_node
      Task.new_from_node(current_node)
    end

    def pick
      task = current
      handle_xml { current_node.remove }
      task
    end

    protected

    def current_node
      root_node.css(ELEMENT).first
    end

    def root_node
      @root_node ||= begin
        xml.css(CURRENT_NODE).first || begin
          node = xml.create_element(CURRENT_NODE)
          super.add_child(node)
          node
        end
      end
    end

    def create_node(task)
      node = super
      node['started_at'] = time_now
      node
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
task_manager2-0.0.16 lib/task_manager/current_task_file.rb
task_manager2-0.0.15 lib/task_manager/current_task_file.rb
task_manager2-0.0.14 lib/task_manager/current_task_file.rb
task_manager2-0.0.13 lib/task_manager/current_task_file.rb