Sha256: 812fc43d0fdfc2c4cd63b2e9136e4a9f3ab41b0c62f053c5f1bcbde2c704d910

Contents?: true

Size: 884 Bytes

Versions: 1

Compression:

Stored size: 884 Bytes

Contents

module <%= class_name %>
  module DisplayNameGlipper
    extend ActiveSupport::Concern

    def blank_display_name
      self.blank_display_name_backward
    end

    def blank_display_name_backward
      self.blank_display_name_assumption ? resource.public_send(self.blank_display_name_assumption) : self.blank_display_name_default
    end

    def blank_display_name_assumptions
      %w{full_name name title subject}
    end

    def blank_display_name_assumption
      Array.wrap(self.blank_display_name_assumptions).find do |method_name|
        resource.respond_to?(method_name) && resource.public_send(method_name).presence
      end
    end

    def blank_display_name_default
      o.id ? "#{resource.class.model_name.human} #{resource.id}" : "New #{resource.class.model_name.human}"
    end

    def display_name(options={})
      self.blank_display_name
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
billet-0.0.1 lib/generators/billet/namespace/templates/drappers/concerns/display_name_glipper.rb.erb