Sha256: bb727e70f6ebd17cad6f4a5dfc6d9bb012625386fdd0e326d710c3b4618a2571

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

require "fileutils"

module PolicyManager
  class JsonExporterView
    attr_accessor :template, :folder, :assigns

    def initialize(vars={}, options)
      self.folder = options[:folder]
      self.assigns = options[:assigns]
      @template = options.fetch(:template) #, self.class.template)
      return self
    end

    def save
      render_json
    end

    def save_json(file, data)
      File.open(file, "w") do |f|
        f.write(data)
      end
    end

    def render_json
      ac = PolicyManager::ExporterController.new()
      options = handled_template.merge!({assigns: self.assigns })
      content = ac.render_to_string(options)
      save_json("#{folder}/data.json", content)
    end

    def handled_template
      begin
        if URI.parse(@template)
          return {template: @template}
        end
      rescue URI::InvalidURIError
      end

      if @template.is_a?(String) 
        return {inline: @template}
      elsif @template.is_a?(Pathname)
        return {file: @template }
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gdpr_rails-0.5.1 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.5.0 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.4.0 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.3.4 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.3.3 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.3.2 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.3.1 lib/policy_manager/exporter/json_view.rb
gdpr_rails-0.3.0 lib/policy_manager/exporter/json_view.rb