Sha256: 200cc29c2047f48aa2cd008e777d3c4a9f8ba4d9aba4470e96c369cad6ffb2f6

Contents?: true

Size: 949 Bytes

Versions: 1

Compression:

Stored size: 949 Bytes

Contents

require 'ostruct'
require 'trellohub/board'

module Trellohub
  class List < OpenStruct
    def id
      @id ||= find_id
    end

    def find_id
      current_list = self.class.find_by(name: name)

      list = case
        when current_list && current_list.closed
          Trell.update_list(current_list.id, closed: false)
        when current_list.nil?
          Trell.create_list(name: name, idBoard: board_id)
        else
          current_list
        end

      list.id
    end

    def board_id
      Trellohub::Board.id
    end

    class << self
      def all
        @all || self.all!
      end

      def all!
        @all = Trell.lists(Trellohub::Board.id)
      end

      def find_by(id: nil, name: nil)
        case
        when !id.nil?
          self.all.find { |list| list.id == id }
        when !name.nil?
          self.all.find { |list| list.name == name }
        else
          nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trellohub-0.1.0 lib/trellohub/list.rb