class Roject::Project

Represents a programming project managed by Roject

Author: Anshul Kharbanda Created: 7 - 10 - 2016

Constants

CONFIG_DEFAULT

Default configuration

FILENAME_DEFAULT

Default filename

Public Class Methods

exist?(filename=FILENAME_DEFAULT) click to toggle source

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
# File lib/project.rb, line 53
def self.exist? filename=FILENAME_DEFAULT
        File.file?(FILENAME_DEFAULT)
end
load(filename=FILENAME_DEFAULT) click to toggle source

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

# File lib/project.rb, line 80
def self.load filename=FILENAME_DEFAULT
        project = self.new
        project.instance_eval(IO.read(filename))
        return project
end
new() click to toggle source

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

# File lib/project.rb, line 90
def initialize; @config = CONFIG_DEFAULT; @makers = {}; end
open(filename=FILENAME_DEFAULT, &block) click to toggle source

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

# 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

Public Instance Methods

config(hash=nil) click to toggle source

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

# File lib/project.rb, line 104
def config(hash=nil); hash and @config.merge!(hash) or return @config; end
file(name, hash) click to toggle source

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

# 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={}) click to toggle source

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

# 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) click to toggle source

Reloads the project with the file with the given filename

Parameter: filename - the name of the file to parse

(defaults to the default filename)
# File lib/project.rb, line 96
def reload(filename=FILENAME_DEFAULT); initialize and instance_eval(IO.read(filename)); end
task(name, &block) click to toggle source

Creates a task maker with the given name and block

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

# File lib/project.rb, line 134
def task(name, &block);
        unless @makers.has_key? name
                @makers[name] = TaskMaker.new &block
        end
end