Sha256: 26ad2f71b8e20e5d2903e0eeb46b156c58ae6b4868cd5ac79cfda79b85312177

Contents?: true

Size: 789 Bytes

Versions: 5

Compression:

Stored size: 789 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, 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

5 entries across 5 versions & 1 rubygems

Version Path
activeadmin_addons-1.1.2 lib/activeadmin_addons/addons/tag_builder.rb
activeadmin_addons-1.1.1 lib/activeadmin_addons/addons/tag_builder.rb
activeadmin_addons-1.1.0 lib/activeadmin_addons/addons/tag_builder.rb
activeadmin_addons-1.0.1 lib/activeadmin_addons/addons/tag_builder.rb
activeadmin_addons-1.0.0 lib/activeadmin_addons/addons/tag_builder.rb