Class: PolicyManager::JsonExporterView
- Inherits:
-
Object
- Object
- PolicyManager::JsonExporterView
- Defined in:
- lib/policy_manager/exporter/json_view.rb
Instance Attribute Summary collapse
-
#assigns ⇒ Object
Returns the value of attribute assigns.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #handled_template ⇒ Object
-
#initialize(vars = {}, options) ⇒ JsonExporterView
constructor
A new instance of JsonExporterView.
- #render_json ⇒ Object
- #save ⇒ Object
- #save_json(file, data) ⇒ Object
Constructor Details
#initialize(vars = {}, options) ⇒ JsonExporterView
Returns a new instance of JsonExporterView.
7 8 9 10 11 12 |
# File 'lib/policy_manager/exporter/json_view.rb', line 7 def initialize(vars={}, ) self.folder = [:folder] self.assigns = [:assigns] @template = .fetch(:template) #, self.class.template) return self end |
Instance Attribute Details
#assigns ⇒ Object
Returns the value of attribute assigns.
5 6 7 |
# File 'lib/policy_manager/exporter/json_view.rb', line 5 def assigns @assigns end |
#folder ⇒ Object
Returns the value of attribute folder.
5 6 7 |
# File 'lib/policy_manager/exporter/json_view.rb', line 5 def folder @folder end |
#template ⇒ Object
Returns the value of attribute template.
5 6 7 |
# File 'lib/policy_manager/exporter/json_view.rb', line 5 def template @template end |
Instance Method Details
#handled_template ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
24 25 26 27 28 29 |
# File 'lib/policy_manager/exporter/json_view.rb', line 24 def render_json ac = PolicyManager::ExporterController.new() = handled_template.merge!({assigns: self.assigns }) content = ac.render_to_string() save_json("#{folder}/data.json", content) end |
#save ⇒ Object
14 15 16 |
# File 'lib/policy_manager/exporter/json_view.rb', line 14 def save render_json end |
#save_json(file, data) ⇒ Object
18 19 20 21 22 |
# 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 |