Sha256: 858614d19537c4142aaccd6a9c6ec8f2aa28b5afa1a5476ae09abdd1a3fa2736

Contents?: true

Size: 1.76 KB

Versions: 13

Compression:

Stored size: 1.76 KB

Contents

module RedmineCrm
  class Settings
    SECTIONS = {
      'money' => { id: :money, label: :label_redmine_crm_money, partial: 'money' }
    }.freeze

    class << self
      def initialize_gem_settings
        return if !Object.const_defined?('Setting') || Setting.respond_to?(:plugin_redmine_crm)

        if Setting.respond_to?(:define_setting)
          Setting.send(:define_setting, 'plugin_redmine_crm', 'default' => default_settings, 'serialized' => true)
        elsif Setting.respond_to?(:available_settings)
          Setting.available_settings['plugin_redmine_crm'] = { 'default' => default_settings, 'serialized' => true }
          Setting.class.send(:define_method, 'plugin_redmine_crm', -> { Setting['plugin_redmine_crm'] })
          Setting.class.send(:define_method, 'plugin_redmine_crm=', lambda do |val|
            setting = find_or_default('plugin_redmine_crm')
            setting.value = val || ''
            @cached_settings['plugin_redmine_crm'] = nil
            setting.save(validate: false)
            setting.value
          end)
        end
        @settings_initialized
      end

      # Use apply instead attrs assign because it can rewrite other attributes
      def apply=(values)
        initialize_gem_settings unless @settings_initialized

        Setting.plugin_redmine_crm = Setting.plugin_redmine_crm.merge(values)
      end

      def values
        initialize_gem_settings unless @settings_initialized
        Object.const_defined?('Setting') ? Setting.plugin_redmine_crm : {}
      end

      def [](value)
        initialize_gem_settings unless @settings_initialized
        return Setting.plugin_redmine_crm[value] if Object.const_defined?('Setting')

        nil
      end

      private

      def default_settings
        {}
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
redmine_crm-0.0.63 lib/redmine_crm/settings.rb
redmine_crm-0.0.62 lib/redmine_crm/settings.rb
redmine_crm-0.0.61 lib/redmine_crm/settings.rb
redmine_crm-0.0.60 lib/redmine_crm/settings.rb
redmine_crm-0.0.59 lib/redmine_crm/settings.rb
redmine_crm-0.0.58 lib/redmine_crm/settings.rb
redmine_crm-0.0.57 lib/redmine_crm/settings.rb
redmine_crm-0.0.56 lib/redmine_crm/settings.rb
redmine_crm-0.0.55 lib/redmine_crm/settings.rb
redmine_crm-0.0.54 lib/redmine_crm/settings.rb
redmine_crm-0.0.53 lib/redmine_crm/settings.rb
redmine_crm-0.0.52 lib/redmine_crm/settings.rb
redmine_crm-0.0.51 lib/redmine_crm/settings.rb