Class: Jsus::Package
- Inherits:
-
Object
- Object
- Jsus::Package
- Defined in:
- lib/jsus/package.rb
Overview
Package is a (self-contained) unit with all the info required to build a javascript package.
Instance Attribute Summary collapse
-
#directory ⇒ Object
directory which this package resides in (full path).
-
#pool ⇒ Object
an instance of Jsus::Pool.
Instance Method Summary collapse
-
#dependencies ⇒ Array
(also: #requires, #requirements)
Array dependencies tags for all source files in the package.
-
#description ⇒ String
A package description.
-
#extensions ⇒ Array
Array with extensions.
-
#filename ⇒ String
A filename for compiled package.
-
#files ⇒ Array
A list of sources filenames.
-
#header ⇒ Hash
Parsed package header.
- #header=(new_header) ⇒ Object private
-
#initialize(directory) ⇒ Package
constructor
Constructors.
-
#name ⇒ String
A package name.
-
#provides ⇒ Array
(also: #provisions)
An array of provided tags.
-
#required_files ⇒ Array
Lists the required files for the package.
-
#source_files ⇒ Array
Array with source files.
-
#to_hash ⇒ Hash
Hash representation of the package.
Constructor Details
#initialize(directory) ⇒ Package
Constructors
Creates a package from given directory.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jsus/package.rb', line 21 def initialize(directory) self.directory = File.(directory) @header = if File.exists?(File.join(directory, 'package.yml')) YAML.load_file(File.join(directory, 'package.yml')) elsif File.exists?(File.join(directory, 'package.json')) JSON.load(Jsus::Util.read_file(File.join(directory, 'package.json'))) else Jsus.logger.fatal "Directory #{directory} does not contain a valid package.yml / package.json file!" raise "Directory #{directory} does not contain a valid package.yml / package.json file!" end Dir.chdir(directory) do files.each do |filename| source_file = SourceFile.from_file(filename, :namespace => name) source_file.package = self if source_file if source_file.extension? extensions << source_file else source_files << source_file end else Jsus.logger.warn "#{filename} is not found for #{name}" end end end end |
Instance Attribute Details
#directory ⇒ Object
directory which this package resides in (full path)
9 10 11 |
# File 'lib/jsus/package.rb', line 9 def directory @directory end |
#pool ⇒ Object
an instance of Jsus::Pool
11 12 13 |
# File 'lib/jsus/package.rb', line 11 def pool @pool end |
Instance Method Details
#dependencies ⇒ Array Also known as: requires, requirements
Returns array dependencies tags for all source files in the package.
90 91 92 93 94 |
# File 'lib/jsus/package.rb', line 90 def dependencies result = source_files.map {|source| source.dependencies }.flatten result -= provides result end |
#description ⇒ String
Returns a package description.
65 66 67 |
# File 'lib/jsus/package.rb', line 65 def description header["description"] ||= "" end |
#extensions ⇒ Array
Array with extensions
129 130 131 |
# File 'lib/jsus/package.rb', line 129 def extensions @extensions ||= [] end |
#filename ⇒ String
Returns a filename for compiled package.
71 72 73 |
# File 'lib/jsus/package.rb', line 71 def filename header["filename"] ||= Jsus::Util::Inflection.snake_case(name) + ".js" end |
#files ⇒ Array
Returns a list of sources filenames.
77 78 79 |
# File 'lib/jsus/package.rb', line 77 def files header["files"] = header["files"] || header["sources"] || [] end |
#header ⇒ Hash
Returns parsed package header.
53 54 55 |
# File 'lib/jsus/package.rb', line 53 def header @header ||= {} end |
#header=(new_header) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
138 139 140 |
# File 'lib/jsus/package.rb', line 138 def header=(new_header) @header = new_header end |
#name ⇒ String
Returns a package name.
59 60 61 |
# File 'lib/jsus/package.rb', line 59 def name header["name"] ||= "" end |
#provides ⇒ Array Also known as: provisions
Returns an array of provided tags.
83 84 85 |
# File 'lib/jsus/package.rb', line 83 def provides source_files.map {|s| s.provides }.flatten end |
#required_files ⇒ Array
Lists the required files for the package.
101 102 103 |
# File 'lib/jsus/package.rb', line 101 def required_files source_files.map {|s| s.required_files }.flatten end |
#source_files ⇒ Array
Array with source files
122 123 124 |
# File 'lib/jsus/package.rb', line 122 def source_files @source_files ||= [] end |
#to_hash ⇒ Hash
Hash representation of the package.
108 109 110 111 112 113 114 115 116 |
# File 'lib/jsus/package.rb', line 108 def to_hash { name => { :description => description, :provides => provides.map {|tag| tag.name }, :requires => requires.map {|tag| tag.namespace == name ? tag.name : tag.full_name } } } end |