Class: Metro::Views::JSONView

Inherits:
Object
  • Object
show all
Defined in:
lib/metro/views/json_view.rb

Overview

Provides support for a JSON Representation of a view.

Class Method Summary collapse

Class Method Details

.exists?(view_path) ⇒ Boolean

Determine if a view exists for this specified format

Parameters:

  • view_path (String)

    the name of the view to find

Returns:

  • (Boolean)

    a true if the json view exists and false if it does not exist.



17
18
19
# File 'lib/metro/views/json_view.rb', line 17

def self.exists?(view_path)
  File.exists? json_view_path(view_path)
end

.formatObject

Returns the file type format of this view.

Returns:

  • the file type format of this view.



34
35
36
# File 'lib/metro/views/json_view.rb', line 34

def self.format
  :json
end

.parse(view_path) ⇒ Object

Parse the contents of the view given the name.

Parameters:

  • view_path (String)

    the name of the view to read

Returns:

  • a Hash that contains the contents of the view.



27
28
29
# File 'lib/metro/views/json_view.rb', line 27

def self.parse(view_path)
  JSON.parse File.read json_view_path(view_path)
end

.write(view_path, content) ⇒ Object

Writes the content out to the spcified view path



41
42
43
44
45
# File 'lib/metro/views/json_view.rb', line 41

def self.write(view_path,content)
  filename = json_view_path(view_path)
  json_content = JSON.pretty_generate(content)
  File.write(filename,json_content)
end