Class: Prigner::Spec

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

Overview

Specification class

This class implements the basic attributes for Template specification.

Constant Summary collapse

DEFAULTS =

Default values.

{
  "options"     => {},
  "directories" => [],
  "files"       => {}
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Spec

Initialize the spec using options in Hash.

Example:

Prigner::Spec.new :author  => "Anakin Skywalker",
                  :email   => "[email protected]",
                  :version => "1.0.0",
                  :options => {
                    "lightsaber" => "Enable red light saber",
                    "force"      => "Use the force"
                  },
                  :directories => %w{galactic/republic galactic/empire},
                  :files       => {
                    "son.erb"    => "jedi/luke_skywalker.knight"
                    "chosen.erb" => "rebels/leia_organa.princess"
                  }


156
157
158
159
160
# File 'lib/prigner.rb', line 156

def initialize(attributes = {})
  DEFAULTS.update(attributes || {}).each do |attribute, value|
    instance_variable_set "@#{attribute}", value if self.respond_to? attribute
  end
end

Instance Attribute Details

#authorObject (readonly)

Author name of template.



113
114
115
# File 'lib/prigner.rb', line 113

def author
  @author
end

#descriptionObject (readonly)

Template description.



122
123
124
# File 'lib/prigner.rb', line 122

def description
  @description
end

#directoriesObject (readonly)

List of directories that will be created in project tree.



128
129
130
# File 'lib/prigner.rb', line 128

def directories
  @directories
end

#emailObject (readonly)

Email for more information about template.



116
117
118
# File 'lib/prigner.rb', line 116

def email
  @email
end

#filesObject (readonly)

List of files that link a model to result file.



131
132
133
# File 'lib/prigner.rb', line 131

def files
  @files
end

#optionsObject (readonly)

Options that enables several features in model files.



125
126
127
# File 'lib/prigner.rb', line 125

def options
  @options
end

#versionObject (readonly)

Template version.



119
120
121
# File 'lib/prigner.rb', line 119

def version
  @version
end

Class Method Details

.load(specfile) ⇒ Object

Load a Specfile and initialize a new Spec that be used in Template.



163
164
165
166
167
# File 'lib/prigner.rb', line 163

def self.load(specfile)
  new(YAML.load_file(specfile))
rescue Exception => error
  raise RuntimeError, "Unable to load Specfile."
end