Class: Turple

Inherits:
Object
  • Object
show all
Defined in:
lib/turple.rb

Defined Under Namespace

Classes: Cli, Data, Interpolate, Template

Constant Summary collapse

@@line_size =

Create CLI Miami presets

80
@@turpleobject =
{
  :template => '',
  :data => {},
  :data_map => {},
  :configuration => {
    # default regex for file names to interpolate content of
    # matches files with an extension of `.turple`
    # (e.g. foo.txt.turple)
    :file_ext => 'turple',
     # default regex for path interpolation
    # make sure to include the path_separator
    # matches capitalized, dot-notated keys surrounded with single brackets
    # (e.g. [FOO.BAR])
    :path_regex => '\[([A-Z_\.]+)\]',
     # default separator for attributes in the path
    # the separator must exist in the path_regex capture group
    # (e.g. [FOO.BAR])
    :path_separator => '.',
     # default regex for content interpolation
    # make sure to include the content_separator
    # matches lowercase, dot-notated keys surrounded with `<>`
    # (e.g. <>foo.bar<>)
    :content_regex => '<>([a-z_\.]+)<>',
     # default separator for attributes in file contents
    # the separator must exist in the content_regex capture group
    # (e.g. <>foo.bar<>)
    :content_separator => '.'
  }
}

Class Method Summary collapse

Class Method Details

.load_turplefile(turplefile_path) ⇒ Hash

Read yaml turplefile and add contents to the turpleobject

Parameters:

  • file (String)

    relative/absolute path to a turplefile

Returns:

  • (Hash)


92
93
94
95
96
97
98
# File 'lib/turple.rb', line 92

def self.load_turplefile turplefile_path
  # return false if file doesnt exist
  turplefile_path = File.expand_path turplefile_path
  return false unless File.exists? turplefile_path

  self.turpleobject = YAML.load File.read turplefile_path
end

.method_missing(method) ⇒ Object

allows helper accessors for turpleobject



83
84
85
# File 'lib/turple.rb', line 83

def self.method_missing method
  self.turpleobject[method] || super
end

.turpleobjectHash

Get loaded turplefiles contents

Returns:

  • (Hash)


79
# File 'lib/turple.rb', line 79

def self.turpleobject; @@turpleobject; end

.turpleobject=(hash) ⇒ Hash

Add additional data to the collective turplefile

Parameters:

  • hash (Hash)

    any hash of data to be merged into existing turplefile data

Returns:

  • (Hash)

    merged turplefile data with symbolized keys



103
104
105
# File 'lib/turple.rb', line 103

def self.turpleobject= hash
  @@turpleobject.deep_merge! hash.deep_symbolize_keys
end