Class: Decidim::OpenDataExporter
- Inherits:
-
Object
- Object
- Decidim::OpenDataExporter
- Includes:
- TranslatableAttributes
- Defined in:
- decidim-core/app/services/decidim/open_data_exporter.rb
Overview
Public: It generates a ZIP file with Open Data CSV files ready to be uploaded somewhere so users can download an organization data.
Constant Summary collapse
- FILE_NAME_PATTERN =
"%{host}-open-data-%{entity}.csv"
Instance Attribute Summary collapse
-
#help_definition ⇒ Object
readonly
Returns the value of attribute help_definition.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(organization, path, resource = nil) ⇒ OpenDataExporter
constructor
Public: Initializes the class.
Methods included from TranslatableAttributes
#attachment?, #default_locale?
Constructor Details
#initialize(organization, path, resource = nil) ⇒ OpenDataExporter
Public: Initializes the class.
organization - The Organization to export the data from. path - The String path where to write the zip file. resource - The String of the component or participatory space to export. If nil, it will export all.
21 22 23 24 25 26 |
# File 'decidim-core/app/services/decidim/open_data_exporter.rb', line 21 def initialize(organization, path, resource = nil) @organization = organization @path = File. path @resource = resource @help_definition = {} end |
Instance Attribute Details
#help_definition ⇒ Object (readonly)
Returns the value of attribute help_definition.
12 13 14 |
# File 'decidim-core/app/services/decidim/open_data_exporter.rb', line 12 def help_definition @help_definition end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
12 13 14 |
# File 'decidim-core/app/services/decidim/open_data_exporter.rb', line 12 def organization @organization end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'decidim-core/app/services/decidim/open_data_exporter.rb', line 12 def path @path end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
12 13 14 |
# File 'decidim-core/app/services/decidim/open_data_exporter.rb', line 12 def resource @resource end |
Instance Method Details
#export ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'decidim-core/app/services/decidim/open_data_exporter.rb', line 28 def export dirname = File.dirname(path) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) if resource.nil? File.binwrite(path, data_for_all_resources) else File.write(path, data_for_resource(resource)) end end |