Class: Decidim::ParticipatorySpaceManifest

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/decidim/participatory_space_manifest.rb

Overview

This class handles all the logic associated to configuring a participatory space, the highest level object of Decidim.

It’s normally not used directly but through the API exposed through ‘Decidim.register_participatory_space`.

Instance Method Summary collapse

Instance Method Details

#context(name = :public, &block) ⇒ Object

A context used to set the layout and behavior of a participatory space. Full documentation can be found looking at the ‘ParticipatorySpaceContextManifest` class.

Example:

context(:public) do |context|
  context.layout "layouts/decidim/some_layout"
end

context(:public).layout
# => "layouts/decidim/some_layout"

Returns Nothing.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/decidim/participatory_space_manifest.rb', line 62

def context(name = :public, &block)
  name = name.to_sym
  @contexts ||= {}

  if block
    context = ParticipatorySpaceContextManifest.new
    context.instance_eval(&block)
    @contexts[name] = context
  end

  @contexts.fetch(name)
end

#participatory_spaces(&block) ⇒ Object

Public: A block that retrieves all the participatory spaces for the manifest. The block receives a ‘Decidim::Organization` as a parameter in order to filter. The block is expected to return an `ActiveRecord::Association`.

Returns nothing.



102
103
104
# File 'lib/decidim/participatory_space_manifest.rb', line 102

def participatory_spaces(&block)
  @participatory_spaces ||= block
end

#permissions_classObject

Public: Finds the permission class from its name, using the ‘permissions_class_name` attribute. If the class does not exist, it raises an exception. If the class name is not set, it returns nil.

Returns a Class.



111
112
113
# File 'lib/decidim/participatory_space_manifest.rb', line 111

def permissions_class
  permissions_class_name&.constantize
end

#register_resource(name, &block) ⇒ Object

Public: Registers a resource. Exposes a DSL defined by ‘Decidim::ResourceManifest`.

Resource manifests are a way to expose a resource from one engine to the whole system. This way resources can be linked between them.

name - A name for that resource. Should be singular (ie not plural). block - A Block that will be called to set the Resource attributes.

Returns nothing.



125
126
127
# File 'lib/decidim/participatory_space_manifest.rb', line 125

def register_resource(name, &block)
  Decidim.register_resource(name, &block)
end

#route_nameObject

The name of the named Rails route to create the url to the resource.

Returns a String.



93
94
95
# File 'lib/decidim/participatory_space_manifest.rb', line 93

def route_name
  super || model_class_name.demodulize.underscore
end

#seed!Object

Public: Creates the seeds for this components in order to populate the database.

Returns nothing.



85
86
87
88
# File 'lib/decidim/participatory_space_manifest.rb', line 85

def seed!
  print "Creating seeds for the #{name} space...\n" unless Rails.env.test?
  @seeds&.call
end

#seeds(&block) ⇒ Object

Public: A block that gets called when seeding for this component takes place.

Returns nothing.



78
79
80
# File 'lib/decidim/participatory_space_manifest.rb', line 78

def seeds(&block)
  @seeds = block
end