Sha256: f29199bed65235cf2f413ff6c0558efbddfde3911d5416126ad9277fc6f2ed40

Contents?: true

Size: 782 Bytes

Versions: 41

Compression:

Stored size: 782 Bytes

Contents

module EasySettings
  ##
  # EasySettings::FormModel
  #
  # Fake models/proxy for easy seettings. Usable in rails form.
  #
  #   settings = EasySettings::FormModel.new(prefix: 'easy_gantt')
  #   settings.show_holidays == EasySetting.value(:easy_gantt_show_holidays)
  #
  class FormModel

    def initialize(prefix: nil, project: nil)
      @prefix = "#{prefix}_" if prefix.present?
      @project_id = project.is_a?(Project) ? project.id : project
    end

    def model_name
      EasySetting.model_name
    end

    def persisted?
      true
    end

    def to_model
      self
    end

    # Called for missing :id parameter
    #
    # def to_param
    # end

    def method_missing(name, *args)
      EasySetting.value("#{@prefix}#{name}", @project_id)
    end

  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
redmine_extensions-1.2.0 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-1.1.2 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-1.1.1 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-1.1.0 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-1.0.0 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.6.3 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.6.2 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.6.1 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.6.0 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.4.5 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.5.1 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.4.4 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.4.3 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.4.1 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.4.0 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.4.0.beta lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.3.11 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.3.10 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.3.9 lib/redmine_extensions/easy_settings/form_model.rb
redmine_extensions-0.3.8 lib/redmine_extensions/easy_settings/form_model.rb