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-4.0.0.beta14 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta13 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta12 lib/active_admin/dynamic_setting.rb
activeadmin-3.2.5 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta11 lib/active_admin/dynamic_setting.rb
activeadmin-3.2.4 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta10 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta9 lib/active_admin/dynamic_setting.rb
activeadmin-3.2.3 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta8 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta7 lib/active_admin/dynamic_setting.rb
activeadmin-3.2.2 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta6 lib/active_admin/dynamic_setting.rb
activeadmin-3.2.1 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta5 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta4 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta3 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta2 lib/active_admin/dynamic_setting.rb
activeadmin-4.0.0.beta1 lib/active_admin/dynamic_setting.rb
activeadmin-3.2.0 lib/active_admin/dynamic_setting.rb