Class: Roject::Project

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/project.rb

Overview

Created: 7 - 10 - 2016

Constant Summary collapse

FILENAME_DEFAULT =

Default filename

"project.rb"
CONFIG_DEFAULT =

Default configuration

{
  project_name: "[project-name]",
  author: "[author]",
  created: "[created]",
  short_description: "[short_description]",
  long_description: "[long_description]",
  directory: {
    templates: "_templates"
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#c_header_id

Constructor Details

#initializeProject

Called upon the initialization of a Project Creates config and makers hashes



90
# File 'lib/project.rb', line 90

def initialize; @config = CONFIG_DEFAULT; @makers = {}; end

Class Method Details

.exist?(filename = FILENAME_DEFAULT) ⇒ Boolean

Check if a project file exists in the current directory

Parameter: filename - the filename to check (defaults to the default filename)

Returns: true if the project file exists in the current directory

Returns:

  • (Boolean)


53
54
55
# File 'lib/project.rb', line 53

def self.exist? filename=FILENAME_DEFAULT
  File.file?(FILENAME_DEFAULT)
end

.load(filename = FILENAME_DEFAULT) ⇒ Object

Loads a Project from the project file with the given filename

Parameter: filename - the name of the file to parse (defaults to the default filename)

Return: Project loaded from the file



80
81
82
83
84
# File 'lib/project.rb', line 80

def self.load filename=FILENAME_DEFAULT
  project = self.new
  project.instance_eval(IO.read(filename))
  return project
end

.open(filename = FILENAME_DEFAULT, &block) ⇒ Object

Alias for load if no block is given. Evaluates the given block in the context of the project if block is given

Parameter: filename - the name of the file to parse (defaults to the default filename) Parameter: block - the block to evaluate within the context of the project

Return: Project loaded from the file



68
69
70
71
72
# File 'lib/project.rb', line 68

def self.open filename=FILENAME_DEFAULT, &block
  project = self.load(filename)
  project.instance_eval(&block) unless block.nil?
  return project
end

Instance Method Details

#config(hash = nil) ⇒ Object

If a hash is given, sets the Project configuration to the hash. Else, returns the configuration of the Project.

Parameter: hash - the hash to configure the project with

Return: the configuration of the Project



104
# File 'lib/project.rb', line 104

def config(hash=nil); hash and @config.merge!(hash) or return @config; end

#file(name, hash) ⇒ Object

Creates a file maker with the given name and hash

Parameter: name - the name of the maker Parameter: hash - the hash arguments of the maker



124
125
126
127
128
# File 'lib/project.rb', line 124

def file(name, hash)
  unless @makers.has_key? name
    @makers[name] = FileMaker.new self, hash
  end
end

#make(name, args) ⇒ Object

Runs the maker of the given name with the given args

Parameter: name - the name of the maker to run Parameter: args - the args to pass to the file



112
113
114
115
116
117
118
# File 'lib/project.rb', line 112

def make(name, args)
  if @makers.has_key? name
    @makers[name].make self, args
  else
    raise RuntimeError, "Undefied maker #{name}"
  end
end

#reload(filename = FILENAME_DEFAULT) ⇒ Object

Reloads the project with the file with the given filename

Parameter: filename - the name of the file to parse (defaults to the default filename)



96
# File 'lib/project.rb', line 96

def reload(filename=FILENAME_DEFAULT); initialize and instance_eval(IO.read(filename)); end

#task(name, &block) ⇒ Object

Creates a task maker with the given name and block

Parameter: name - the name of the recipie Parameter: block - the recipie block



134
135
136
137
138
# File 'lib/project.rb', line 134

def task(name, &block);
  unless @makers.has_key? name
    @makers[name] = TaskMaker.new &block
  end
end