class Trellohub::Form

Public Class Methods

array_ext() click to toggle source
# File lib/trellohub/form.rb, line 25
      def array_ext
        <<-METHODS
          def find_by_key(key)
            self.find { |form| form.key == key }
          end
        METHODS
      end
common_attributes() click to toggle source
# File lib/trellohub/form.rb, line 10
def common_attributes
  %i(
    key
    state
    imported_from
  )
end
compare(base, target) click to toggle source
# File lib/trellohub/form.rb, line 68
def compare(base, target)
  return unless base.updated_at < target.updated_at
  type = target.imported_from

  printings = [[
    "#{type} attribute",
    "#{'base'.green} (#{base.imported_from}: #{base.own_key}, #{base.updated_at})",
    "#{'comparison'.yellow} (#{target.imported_from}: #{target.own_key}, #{target.updated_at})"
  ]] if Trellohub.debug

  diff = target.send(:"to_valid_#{type}").each.with_object({}) do |(key, value), hash|
    base_value = base.send(:"to_valid_#{type}")[key]
    hash[key] = value unless value == base_value

    printings << [
      key,
      base_value.to_s.color(value == base_value ? :green : :red),
      value.to_s.yellow
    ] if Trellohub.debug
  end

  if Trellohub.debug && !diff.empty?
    max = printings.max_lengths
    printings.each.with_index(1) do |line, index|
      puts '[DIFF: Update the base]' if index == 1
      puts 3.times.map.with_index { |i| ''.ljust(max[i], '-') }.join(' | ') if index == 2
      puts line.map.with_index { |word, i| "#{word}".ljust(max[i]) }.join(' | ')
    end
  end

  diff unless diff.empty?
end
origin_attributes() click to toggle source
# File lib/trellohub/form.rb, line 18
def origin_attributes
  %i(
    origin_issue
    origin_card
  )
end
with_cards() click to toggle source
# File lib/trellohub/form.rb, line 53
def with_cards
  @cards ||= self.with_cards!
end
with_cards!() click to toggle source
# File lib/trellohub/form.rb, line 57
def with_cards!
  array = Trellohub::Card.all.
    each.with_object([]) do |card, forms|
    form = Trellohub::Form.new
    form.import_card card
    forms << form
  end
  array.instance_eval array_ext
  array
end
with_issues() click to toggle source
# File lib/trellohub/form.rb, line 33
def with_issues
  @issues ||= self.with_issues!
end
with_issues!() click to toggle source
# File lib/trellohub/form.rb, line 37
def with_issues!
  array = Trellohub.repositories.each.with_object([]) do |repo, forms|
    forms.concat with_issues_on(repo)
  end
  array.instance_eval array_ext
  array
end
with_issues_on(repo) click to toggle source
# File lib/trellohub/form.rb, line 45
def with_issues_on(repo)
  repo.issues.each.with_object([]) do |issue, forms|
    form = Trellohub::Form.new
    form.import_issue repo.full_name, issue
    forms << form
  end
end

Public Instance Methods

closed?() click to toggle source
# File lib/trellohub/form.rb, line 122
def closed?
  @state == 'closed'
end
closed_at() click to toggle source
# File lib/trellohub/form.rb, line 113
def closed_at
  return @issue_closed_at if @imported_from == :issue
  @closed_at ||= card_closed_at || card_created_at
end
created_at() click to toggle source
# File lib/trellohub/form.rb, line 104
def created_at
  @created_at ||= send(:"#{@imported_from}_#{__method__}")
end
open?() click to toggle source
# File lib/trellohub/form.rb, line 118
def open?
  @state == 'open'
end
own_key() click to toggle source
# File lib/trellohub/form.rb, line 126
def own_key
  if @imported_from == :issue
    @key
  else
    @card_shortLink
  end
end
to_hash() click to toggle source
# File lib/trellohub/form.rb, line 134
def to_hash
  Hash[instance_variables.map { |variable|
    next if variable.is_a?(Sawyer::Resource)
    variable_no_at = variable.to_s.gsub('@', '')
    [variable_no_at.to_sym, instance_variable_get(:"#{variable}")]
  }.compact]
end
updated_at() click to toggle source
# File lib/trellohub/form.rb, line 108
def updated_at
  return @issue_updated_at if @imported_from == :issue
  @updated_at ||= card_updated_at || card_created_at
end