Sha256: 18d3073a0fe35a4d60442a2a2f098b7d4243f08ecbccdc99d0f25398f8e68f9f

Contents?: true

Size: 1.34 KB

Versions: 25

Compression:

Stored size: 1.34 KB

Contents

require 'hammer_cli'

module Fields

  class Reference < Field
    def initialize(options={})
      super
      initialize_options
    end

    def initialize_options
      @options[:details] ||= []
      @options[:details] = [@options[:details]] unless @options[:details].is_a?(Array)
      @options[:details] = [id_detail] + @options[:details]
      @options[:display_field_key] ||= @options[:name_key] || :name
    end

    protected

    def id_detail
      {
        :label => _('id'),
        :structured_label => _('Id'),
        :key => @options[:id_key] || :id,
        :id => true
      }
    end
  end

  class SingleReference < Reference
    def initialize_options
      key = @options[:key]
      display_field = @options[:display_field] || 'name'

      @options[:id_key] ||= "#{key}_id"
      @options[:display_field_key] ||= "#{key}_#{display_field}"
      super
    end

    def display?(value)
      id_key = @options[:id_key]
      display_key = @options[:display_field_key]

      (value[display_key.to_sym] || value[display_key]) && (value[id_key.to_sym] || value[id_key])
    end
  end

  class Template < Reference
    def initialize_options
      super
      @options[:details] << template_kind_detail
    end

    def template_kind_detail
      {
        :structured_label => _('Kind'),
        :key => :template_kind_name,
      }
    end
  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hammer_cli_foreman-2.1.3 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-2.1.2 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-2.1.1 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-2.1.0 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-2.0.2 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-2.0.1 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-2.0.0 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.7 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.6 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.5 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.4 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.3 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.2 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.18.2 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.1 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.18.1 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.19.0 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.17.2 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.18.0 lib/hammer_cli_foreman/output/fields.rb
hammer_cli_foreman-0.17.1 lib/hammer_cli_foreman/output/fields.rb