Class: Metro::Views::YAMLView

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

Class Method Summary collapse

Class Method Details

.default_extnameObject

Returns the default extension to use when saving yaml files.

Returns:

  • the default extension to use when saving yaml files.



48
49
50
# File 'lib/metro/views/yaml_view.rb', line 48

def self.default_extname
  @default_extname || ".yaml"
end

.default_extname=(value) ⇒ Object

Set the default extname

Examples:


Metro::Views::YAMLView.default_extname = ".yml"


59
60
61
# File 'lib/metro/views/yaml_view.rb', line 59

def self.default_extname=(value)
  @default_extname = value
end

.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 yaml view exists and false if it does not exist.



14
15
16
# File 'lib/metro/views/yaml_view.rb', line 14

def self.exists?(view_path)
  yaml_view_paths(view_path).find { |view_path| File.exists? view_path }
end

.formatObject

Returns the file type format of this view.

Returns:

  • the file type format of this view.



31
32
33
# File 'lib/metro/views/yaml_view.rb', line 31

def self.format
  :yaml
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.



24
25
26
# File 'lib/metro/views/yaml_view.rb', line 24

def self.parse(view_path)
  YAML.load(File.read(yaml_view_path(view_path))) or { }
end

.write(view_path, content) ⇒ Object

Parameters:

  • view_path (String)

    the file path to the view which to save the content

  • content (Hash)

    the content to save within the view



39
40
41
42
43
# File 'lib/metro/views/yaml_view.rb', line 39

def self.write(view_path,content)
  filename = write_filepath(view_path)
  yaml_content = content.to_yaml
  File.write(filename,yaml_content)
end