class PolicyManager::JsonExporterView
Attributes
assigns[RW]
folder[RW]
template[RW]
Public Class Methods
new(vars={}, options)
click to toggle source
# File lib/policy_manager/exporter/json_view.rb, line 7 def initialize(vars={}, options) self.folder = options[:folder] self.assigns = options[:assigns] @template = options.fetch(:template) #, self.class.template) return self end
Public Instance Methods
handled_template()
click to toggle source
# File lib/policy_manager/exporter/json_view.rb, line 31 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
render_json()
click to toggle source
# File lib/policy_manager/exporter/json_view.rb, line 24 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
save()
click to toggle source
# File lib/policy_manager/exporter/json_view.rb, line 14 def save render_json end
save_json(file, data)
click to toggle source
# File lib/policy_manager/exporter/json_view.rb, line 18 def save_json(file, data) File.open(file, "w") do |f| f.write(data) end end