Class: Ecic::Project
- Inherits:
-
Object
- Object
- Ecic::Project
- Defined in:
- lib/ecic/project.rb
Constant Summary collapse
- SCRIPT_ECIC =
File.join('src', 'config', 'ecic.rb')
- LIBRARIES_CFG_SCRIPT =
File.join('src', 'config', 'libraries.rb')
Instance Attribute Summary collapse
-
#libraries ⇒ Object
Returns the value of attribute libraries.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
-
.root(path = Pathname.new(Dir.pwd)) ⇒ Object
Function that returns the root directory of a ECIC project This is used by some generators to check if a command is called from within an ECIC project folder.
Instance Method Summary collapse
- #add_library(lib) ⇒ Object
-
#design_library(name, options = {}) ⇒ Object
Function used in src/confic/libraries.rb.
- #get_library(lib_name) ⇒ Object
- #has_library?(library) ⇒ Boolean
-
#initialize(root = Project::root) ⇒ Project
constructor
A new instance of Project.
- #library_mapped_to(path) ⇒ Object
- #load_libraries ⇒ Object
- #load_sources ⇒ Object
-
#testbench_library(name, options = {}) ⇒ Object
Function used in src/confic/libraries.rb.
Constructor Details
Instance Attribute Details
#libraries ⇒ Object
Returns the value of attribute libraries.
5 6 7 |
# File 'lib/ecic/project.rb', line 5 def libraries @libraries end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/ecic/project.rb', line 6 def root @root end |
Class Method Details
.root(path = Pathname.new(Dir.pwd)) ⇒ Object
Function that returns the root directory of a ECIC project This is used by some generators to check if a command is called from within an ECIC project folder
21 22 23 24 25 26 27 28 |
# File 'lib/ecic/project.rb', line 21 def self.root(path = Pathname.new(Dir.pwd)) if File.exists?(File.join(path, SCRIPT_ECIC)) return File.(path) elsif path.root? return nil end return root(path.parent) end |
Instance Method Details
#add_library(lib) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/ecic/project.rb', line 59 def add_library(lib) raise "A library called '#{lib.name}' already exists" if has_library?(lib) raise "A library is already mapped to '#{lib.path}'" if library_mapped_to(lib.path) @libraries << lib return true end |
#design_library(name, options = {}) ⇒ Object
Function used in src/confic/libraries.rb
67 68 69 |
# File 'lib/ecic/project.rb', line 67 def design_library(name, ={}) Library.new(self, name, :design, ) end |
#get_library(lib_name) ⇒ Object
53 54 55 56 57 |
# File 'lib/ecic/project.rb', line 53 def get_library(lib_name) matching_libraries = libraries.select {|l| l.name.eql? lib_name } raise "Found multiple libraries called '#{lib_name}'" if matching_libraries.length > 1 matching_libraries.first end |
#has_library?(library) ⇒ Boolean
43 44 45 |
# File 'lib/ecic/project.rb', line 43 def has_library?(library) libraries.any? {|l| l.name.eql? library.name} end |
#library_mapped_to(path) ⇒ Object
47 48 49 50 51 |
# File 'lib/ecic/project.rb', line 47 def library_mapped_to(path) matching_libraries = libraries.select {|l| l.path.eql? path } raise "Found multiple libraries mapped to '#{path}'" if matching_libraries.length > 1 matching_libraries.first end |
#load_libraries ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ecic/project.rb', line 30 def load_libraries lib_file = File.join(@root, LIBRARIES_CFG_SCRIPT) if File.exists?(lib_file) begin eval File.read(lib_file) rescue Exception => exc raise "Syntax error occurred while reading #{lib_file}: #{exc.}" end # else # raise "Could not read library definitions from #{lib_file}" end end |
#load_sources ⇒ Object
76 77 78 |
# File 'lib/ecic/project.rb', line 76 def load_sources libraries.each { |lib| lib.load_sources } end |