Class: Decidim::DecidimAwesome::Config
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::Config
- Defined in:
- lib/decidim/decidim_awesome/config.rb
Overview
The current awesome config for the organization.
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
- #defaults ⇒ Object
Instance Method Summary collapse
-
#config ⇒ Object
config processed in context.
-
#context_from_component(component) ⇒ Object
convert component to manifest, slug and id.
-
#context_from_participatory_space(space) ⇒ Object
convert participatory space to manifest, slug and id.
-
#context_from_request(request) ⇒ Object
convert context to manifest, slug and id.
-
#enabled_for?(setting) ⇒ Boolean
Checks if some config option es enabled in a certain context.
-
#initialize(organization) ⇒ Config
constructor
A new instance of Config.
-
#organization_config ⇒ Object
config processed for the organization config, without context.
- #setting_for(var) ⇒ Object
-
#unfiltered_config ⇒ Object
config normalized according default values, without context, without organization config.
Constructor Details
#initialize(organization) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/decidim/decidim_awesome/config.rb', line 7 def initialize(organization) @organization = organization @vars = AwesomeConfig.for_organization(organization).includes(:constraints) @context = { participatory_space_manifest: nil, participatory_slug: nil, component_id: nil, component_manifest: nil } end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
18 19 20 |
# File 'lib/decidim/decidim_awesome/config.rb', line 18 def context @context end |
#defaults ⇒ Object
21 22 23 |
# File 'lib/decidim/decidim_awesome/config.rb', line 21 def defaults @defaults || Decidim::DecidimAwesome.config end |
Instance Method Details
#config ⇒ Object
config processed in context
49 50 51 |
# File 'lib/decidim/decidim_awesome/config.rb', line 49 def config @config ||= calculate_config end |
#context_from_component(component) ⇒ Object
convert component to manifest, slug and id
37 38 39 40 |
# File 'lib/decidim/decidim_awesome/config.rb', line 37 def context_from_component(component) @config = nil @context = Decidim::DecidimAwesome::ContextAnalyzers::ComponentAnalyzer.context_for component end |
#context_from_participatory_space(space) ⇒ Object
convert participatory space to manifest, slug and id
43 44 45 46 |
# File 'lib/decidim/decidim_awesome/config.rb', line 43 def context_from_participatory_space(space) @config = nil @context = Decidim::DecidimAwesome::ContextAnalyzers::ParticipatorySpaceAnalyzer.context_for space end |
#context_from_request(request) ⇒ Object
convert context to manifest, slug and id
31 32 33 34 |
# File 'lib/decidim/decidim_awesome/config.rb', line 31 def context_from_request(request) @config = nil @context = Decidim::DecidimAwesome::ContextAnalyzers::RequestAnalyzer.context_for request end |
#enabled_for?(setting) ⇒ Boolean
Checks if some config option es enabled in a certain context
78 79 80 |
# File 'lib/decidim/decidim_awesome/config.rb', line 78 def enabled_for?(setting) config[setting] end |
#organization_config ⇒ Object
config processed for the organization config, without context
54 55 56 57 58 59 |
# File 'lib/decidim/decidim_awesome/config.rb', line 54 def organization_config @organization_config ||= unfiltered_config.map do |key, value| value = defaults[key] unless enabled_for_organization? key [key, value] end.to_h end |
#setting_for(var) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/decidim/decidim_awesome/config.rb', line 70 def setting_for(var) @vars.find_or_initialize_by( organization: @organization, var: var ) end |
#unfiltered_config ⇒ Object
config normalized according default values, without context, without organization config
62 63 64 65 66 67 68 |
# File 'lib/decidim/decidim_awesome/config.rb', line 62 def unfiltered_config valid = @vars.map { |v| [v.var.to_sym, v.value] }.to_h map_defaults do |key| valid[key].presence end end |