Class: Decidim::DecidimAwesome::Admin::CreateScopedStyle

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/decidim_awesome/admin/create_scoped_style.rb

Instance Method Summary collapse

Constructor Details

#initialize(organization) ⇒ CreateScopedStyle

Public: Initializes the command.



9
10
11
12
# File 'app/commands/decidim/decidim_awesome/admin/create_scoped_style.rb', line 9

def initialize(organization)
  @organization = organization
  @ident = rand(36**8).to_s(36)
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if we couldn’t proceed.

Returns nothing.



20
21
22
23
24
25
26
27
28
29
30
# File 'app/commands/decidim/decidim_awesome/admin/create_scoped_style.rb', line 20

def call
  styles = AwesomeConfig.find_or_initialize_by(var: :scoped_styles, organization: @organization)
  styles.value = {} unless styles.value.is_a? Hash
  # TODO: prevent (unlikely) colisions with exisiting values
  styles.value[@ident] = ""
  styles.save!

  broadcast(:ok, @ident)
rescue StandardError => e
  broadcast(:invalid, e.message)
end