<commit_before>module Adminable
  module Presenters
    class Entry < Base
      def initialize(entry)
        @entry = entry
      end

      def to_name
        %i(name title email login id).each do |method_name|
          begin
            return entry.public_send(method_name)
          rescue NoMethodError
            next
          end
        end
      end

      def link_to_self
        return to_name unless resource

        view.link_to(
          to_name,
          edit_polymorphic_path(entry),
          target: '_blank'
        )
      end

      def link_to_delete
        view.link_to(
          I18n.t('adminable.buttons.delete'),
          polymorphic_path(@entry),
          class: 'btn btn-danger-outline pull-xs-right',
          method: :delete,
          data: {
            confirm: I18n.t('adminable.ui.confirm')
          }
        )
      end

      def link_to_edit_small
        view.link_to(
          I18n.t('adminable.buttons.edit'),
          edit_polymorphic_path(entry),
          class: 'label label-primary'
        )
      end

      def link_to_delete_small
        view.link_to(
          I18n.t('adminable.buttons.delete'),
          polymorphic_path(entry),
          class: 'label label-danger',
          method: :delete,
          data: {
            confirm: I18n.t('adminable.ui.confirm')
          }
        )
      end

      def method_missing(method_name, *args, &block)
        entry.public_send(method_name, *args, &block)
      end

      def respond_to_missing?(method_name, *)
        entry.respond_to?(method_name)
      end

      private
<commit_msg>Refactor entry presenter, add has_one_value method<commit_after>module Adminable
  module Presenters
    class Entry < Base
      def initialize(entry, field: nil)
        @entry = entry
        @field = field
        @value = entry.public_send(field.name) if field
      end

      def to_name
        %i(name title email login id).each do |method_name|
          begin
            return entry.public_send(method_name)
          rescue NoMethodError
            next
          end
        end
      end

      def link_to_self
        return to_name unless resource

        view.link_to(
          to_name,
          edit_polymorphic_path(entry),
          target: '_blank'
        )
      end

      def link_to_delete
        view.link_to(
          I18n.t('adminable.buttons.delete'),
          polymorphic_path(@entry),
          class: 'btn btn-danger-outline pull-xs-right',
          method: :delete,
          data: {
            confirm: I18n.t('adminable.ui.confirm')
          }
        )
      end

      def link_to_edit_small
        view.link_to(
          I18n.t('adminable.buttons.edit'),
          edit_polymorphic_path(entry),
          class: 'label label-primary'
        )
      end

      def link_to_delete_small
        view.link_to(
          I18n.t('adminable.buttons.delete'),
          polymorphic_path(entry),
          class: 'label label-danger',
          method: :delete,
          data: {
            confirm: I18n.t('adminable.ui.confirm')
          }
        )
      end

      def has_one_value
        association = @entry.association(@field.name).klass

        if @value
          Adminable::Presenters::Entry(@value).link_to_self
        else
          view.link_to(
            I18n.t(
              'adminable.ui.no_has_one',
              resource: association.model_name.human
            ),
            polymorphic_path(association),
          )
        end
      end

      def method_missing(method_name, *args, &block)
        entry.public_send(method_name, *args, &block)
      end

      def respond_to_missing?(method_name, *)
        entry.respond_to?(method_name)
      end

      private

{'fraction_non_alphanumeric': 0.08512902367650971, 'fraction_numerical': 0.005852620377760042, 'mean_word_length': 1.6056826056826057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '799027', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1101, 'n_words': 215}