Sha256: 8e55f3bd3c383646b3b2b8ae5dc4c7945fe142f2eb49a55c04dd98dfe2a3f2b7

Contents?: true

Size: 952 Bytes

Versions: 31

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true
module ActiveAdmin

  class DynamicSetting
    def self.build(setting, type)
      (type ? klass(type) : self).new(setting)
    end

    def self.klass(type)
      klass = "#{type.to_s.camelcase}Setting"
      raise ArgumentError, "Unknown type: #{type}" unless ActiveAdmin.const_defined?(klass)
      ActiveAdmin.const_get(klass)
    end

    def initialize(setting)
      @setting = setting
    end

    def value(*_args)
      @setting
    end
  end

  # Many configuration options (Ex: site_title, title_image) could either be
  # static (String), methods (Symbol) or procs (Proc). This wrapper takes care of
  # returning the content when String or using instance_eval when Symbol or Proc.
  #
  class StringSymbolOrProcSetting < DynamicSetting
    def value(context = self)
      case @setting
      when Symbol, Proc
        context.instance_eval(&@setting)
      else
        @setting
      end
    end
  end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
activeadmin-3.1.0 lib/active_admin/dynamic_setting.rb
activeadmin-3.0.0 lib/active_admin/dynamic_setting.rb
activeadmin-2.14.0 lib/active_admin/dynamic_setting.rb
activeadmin-2.13.1 lib/active_admin/dynamic_setting.rb
activeadmin-2.13.0 lib/active_admin/dynamic_setting.rb
activeadmin-2.12.0 lib/active_admin/dynamic_setting.rb
activeadmin-2.11.2 lib/active_admin/dynamic_setting.rb
activeadmin-2.11.1 lib/active_admin/dynamic_setting.rb
activeadmin-2.11.0 lib/active_admin/dynamic_setting.rb
activeadmin-2.10.1 lib/active_admin/dynamic_setting.rb
activeadmin-2.10.0 lib/active_admin/dynamic_setting.rb