Sha256: 0ea9c60333133435df50f3d3fdf97e920068441f95aa5d39a9be99ba06a55ff8

Contents?: true

Size: 669 Bytes

Versions: 1

Compression:

Stored size: 669 Bytes

Contents

# frozen_string_literal: true

module ActionLink
  # Extracts a model from the provided i18n options.
  class TitleSubjectName
    include Calls

    option :manual_title
    option :manual_i18n_model
    option :model

    def call
      manual_title || compliant_model.model_name.human
    end

    private

    def compliant_model
      compliant_manual_model || model
    end

    def compliant_manual_model
      return unless manual_i18n_model
      return manual_i18n_model if manual_i18n_model.respond_to?(:model_name)

      raise ArgumentError,
            "Expected `i18n_model:` `#{manual_i18n_model.inspect}` to respond to `#model_name`"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_link-0.1.1 lib/action_link/title_subject_name.rb