Class: EasySettings::FormModel

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine_extensions/easy_settings/form_model.rb

Overview

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)

Instance Method Summary collapse

Constructor Details

#initialize(prefix: nil, project: nil) ⇒ FormModel

Returns a new instance of FormModel.



12
13
14
15
# File 'lib/redmine_extensions/easy_settings/form_model.rb', line 12

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Called for missing :id parameter

def to_param end



34
35
36
# File 'lib/redmine_extensions/easy_settings/form_model.rb', line 34

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

Instance Method Details

#model_nameObject



17
18
19
# File 'lib/redmine_extensions/easy_settings/form_model.rb', line 17

def model_name
  EasySetting.model_name
end

#persisted?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/redmine_extensions/easy_settings/form_model.rb', line 21

def persisted?
  true
end

#to_modelObject



25
26
27
# File 'lib/redmine_extensions/easy_settings/form_model.rb', line 25

def to_model
  self
end