Class: Fdbq::Plugin

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fdbq/plugin.rb

Constant Summary collapse

DEFAULT_PARAM_KEY =
:feedback

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_file_pathObject

Returns the value of attribute config_file_path.



10
11
12
# File 'lib/fdbq/plugin.rb', line 10

def config_file_path
  @config_file_path
end

#controller_extensionsObject

Returns the value of attribute controller_extensions.



12
13
14
# File 'lib/fdbq/plugin.rb', line 12

def controller_extensions
  @controller_extensions
end

#model_extensionsObject

Returns the value of attribute model_extensions.



13
14
15
# File 'lib/fdbq/plugin.rb', line 13

def model_extensions
  @model_extensions
end

#param_keyObject

Returns the value of attribute param_key.



11
12
13
# File 'lib/fdbq/plugin.rb', line 11

def param_key
  @param_key
end

Instance Method Details

#build_param_key(question_name) ⇒ Object



40
41
42
# File 'lib/fdbq/plugin.rb', line 40

def build_param_key(question_name)
  "#{param_key}[#{question_name}]"
end

#configObject



36
37
38
# File 'lib/fdbq/plugin.rb', line 36

def config
  YAML.load_file(config_file_path).to_h
end

#questionsObject



24
25
26
# File 'lib/fdbq/plugin.rb', line 24

def questions
  config.dig('questions').to_a.map(&Question.method(:new))
end

#reset!Object



19
20
21
22
# File 'lib/fdbq/plugin.rb', line 19

def reset!
  self.param_key = DEFAULT_PARAM_KEY
  self.config_file_path = nil
end

#settingsObject



28
29
30
31
32
33
34
# File 'lib/fdbq/plugin.rb', line 28

def settings
  config.tap do |c|
    c['questions']&.map! { |el| el.merge('name' => build_param_key(el['name'])) }

    c['submit'] = { url: Rails::Engine.routes.url_helpers.feedback_path }
  end
end