Sha256: c62f4a957de3d4e902cc19372f30cef4dd91710dc2a8e315fd6e20ff1cf8443d

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require "hanami/view"
require "refinements/string"

module Milestoner
  module Views
    module Parts
      # The tag presentation logic.
      class Tag < Hanami::View::Part
        include Import[:settings]

        using Refinements::String

        decorate :commits
        decorate :author, as: :user

        def avatar_url user
          warn "`#{self.class}##{__method__}` is deprecated, use user scope instead.",
               category: :deprecated

          format settings.avatar_uri, id: user.external_id
        end

        def commit_count = value.commits.size

        def committed_at fallback: Time.now
          value.committed_at.then { |at| at ? Time.at(at) : fallback }
        end

        def committed_date = committed_at.strftime "%Y-%m-%d"

        def committed_datetime = committed_at.strftime "%Y-%m-%dT%H:%M:%S%z"

        def deletion_count = value.commits.sum(&:deletions)

        def empty? = value.commits.empty?

        def profile_url user
          warn "`#{self.class}##{__method__}` is deprecated, use user scope instead.",
               category: :deprecated

          format settings.profile_uri, id: user.handle
        end

        def file_count = value.commits.sum(&:files_changed)

        def insertion_count = value.commits.sum(&:insertions)

        def security = value.signature ? "🔒 Tag (secure)" : "🔓 Tag (insecure)"

        def total_commits = commit_count.then { |total| "#{total} commit".pluralize "s", total }

        def total_files = file_count.then { |total| "#{total} file".pluralize "s", total }

        def total_deletions
          deletion_count.then { |total| "#{total} deletion".pluralize "s", total }
        end

        def total_insertions
          insertion_count.then { |total| "#{total} insertion".pluralize "s", total }
        end

        def uri = format settings.project_uri_version, id: value.version
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
milestoner-18.12.0 lib/milestoner/views/parts/tag.rb
milestoner-18.11.0 lib/milestoner/views/parts/tag.rb