Sha256: 645d33d3b731e07a0b7723ca6762d679b817950b7206961ff9e3124e864d2d34

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 Bytes

Contents

module ActiveAdminAddons
  class TagBuilder < CustomBuilder
    def render
      @enum_attr = if enumerize_attr?
                     :enumerize
                   elsif rails_enum_attr?
                     :enum
                   end

      raise "you need to pass an enumerize or enum attribute" unless @enum_attr
      context.status_tag(display_data, class: data)
    end

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

    def enumerize_attr?
      data.is_a?("Enumerize::Value".constantize)
    rescue NameError
      false
    end

    def rails_enum_attr?
      defined? Rails && Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 1 &&
        model.defined_enums[attribute.to_s]
    end
  end
end

ActiveAdminAddons::TagBuilder.create_view_methods

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin_addons-1.3.0 lib/activeadmin_addons/addons/tag_builder.rb
activeadmin_addons-1.2.0 lib/activeadmin_addons/addons/tag_builder.rb