Sha256: c5a3d1cb7c02b39e52c61e0ce75b139e9d8234112fbeef017387bb59238d3846

Contents?: true

Size: 934 Bytes

Versions: 3

Compression:

Stored size: 934 Bytes

Contents

module ActiveAdminAddons
  class EnumBuilder < CustomBuilder
    def render
      @is_enum = false
      @is_enum = :enumerize if data.is_a?('Enumerize::Value'.constantize)
      if defined? Rails && Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 1
        @is_enum = :enum if model.defined_enums[attribute.to_s]
      end
      raise 'you need to pass an enumerize or enum attribute' unless @is_enum
      context.status_tag(display_data, data)
    end

    def display_data
      @is_enum == :enumerize ? data.text : data
    end
  end

  module ::ActiveAdmin
    module Views
      class TableFor
        def tag_column(*args, &block)
          column(*args) { |model| EnumBuilder.render(self, model, *args, &block) }
        end
      end
      class AttributesTable
        def tag_row(*args, &block)
          row(*args) { |model| EnumBuilder.render(self, model, *args, &block) }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activeadmin_addons-0.9.0 lib/activeadmin_addons/addons/enum_tag.rb
activeadmin_addons-0.8.0 lib/activeadmin_addons/addons/enum_tag.rb
activeadmin_addons-0.7.0 lib/activeadmin_addons/addons/enum_tag.rb