Class: Sprout::Library
- Inherits:
-
Object
- Object
- Sprout::Library
- Includes:
- RubyFeature
- Defined in:
- lib/sprout/library.rb
Overview
Sprout Libraries provide support for sharing and versioning raw or pre-compiled source code across projects.
Sprout Libraries give us the ability to include raw (or pre-compiled) source code directly within a Ruby Gem, or to refer to an archive somewhere on the internet.
A Sprout Library is made up of two components:
-
Specification: The description of the library
-
Source Code: Raw or pre-compiled (swc, jar, abc)
Specification
Libraries can be added to local or remote file targets in a Sprout::Specification. When calling add_library, one must provide the library name (symbol that will be used from Rake) and a relative path (or Array of paths) from the Specification to the library file or directory.
Following is an example of a Sprout::Specification that registers a SWC that will be distributed directly within a Ruby Gem:
Sprout::Specification.new do |s| s.name = "asunit4" s.version = "4.4.2" s.add_file_target do |f| f.add_library :swc, File.join('bin', "AsUnit-4.4.2.swc") end end
Following is an example of a Sprout::Specification that registers a ZIP archive that will be distributed separately from the Ruby Gem:
Sprout::Specification.new do |s| s.name = "asunit3" s.version = "3.0.0" s.add_remote_file_target do |f| f.url = "https://github.com/patternpark/asunit/tree/3.0.0" f.md5 = "abcdefghijklmnopqrstuvwxyz" f.add_library :swc, "bin/AsUnit-3.0.1.zip" end end
Libraries can be consumed from any Rakefile without concern for how the source code is distributed. Following is an example Rake task that uses the AsUnit 4.0 Library:
# Define the library Rake::Task: library :asunit4 # Add the library as a dependency from another task # that should know how to properly associate the files: mxmlc 'bin/SomeProject.swf' => :asunit4 do |t| t.input = 'src/SomeProject.as' end
When the library task is executed, the library should be resolved and expanded into the project. When the mxmlc task is executed, the installed library should be associated with the compilation command.
Flash Libraries
Following are links to the Specifications for some of the existing libraries:
Previous Topic: Generator
Next Topic: Executable
Constant Summary
- TASK_NAME =
:resolve_sprout_libraries
Instance Attribute Summary (collapse)
-
- (Object) file_target
Returns the value of attribute file_target.
-
- (Object) installed_project_path
Returns the value of attribute installed_project_path.
-
- (Object) name
Returns the value of attribute name.
-
- (Object) path
Returns the value of attribute path.
-
- (Object) pkg_name
Returns the value of attribute pkg_name.
-
- (Object) pkg_version
Returns the value of attribute pkg_version.
-
- (Object) platform
Returns the value of attribute platform.
Class Method Summary (collapse)
-
+ (Object) define_task(name = nil, pkg_name = nil, pkg_version = nil)
Create Rake tasks that will load and install a particular library into the current project.
-
+ (Object) project_path
The path within a project where libraries should be added.
-
+ (Object) project_path=(path)
Set the path within a project where libraries should be loaded.
Instance Method Summary (collapse)
-
- (Object) create_installation_tasks
Returns the outer Rake::Task which is invokable.
- - (Object) create_outer_task
-
- (Library) initialize(params = nil)
constructor
A new instance of Library.
Methods included from Concern
#append_features, extended, #included
Constructor Details
- (Library) initialize(params = nil)
A new instance of Library
142 143 144 145 |
# File 'lib/sprout/library.rb', line 142 def initialize params=nil params.each {|key,value| self.send("#{key}=", value)} unless params.nil? super() end |
Instance Attribute Details
- (Object) file_target
Returns the value of attribute file_target
90 91 92 |
# File 'lib/sprout/library.rb', line 90 def file_target @file_target end |
- (Object) installed_project_path
Returns the value of attribute installed_project_path
91 92 93 |
# File 'lib/sprout/library.rb', line 91 def installed_project_path @installed_project_path end |
- (Object) name
Returns the value of attribute name
92 93 94 |
# File 'lib/sprout/library.rb', line 92 def name @name end |
- (Object) path
Returns the value of attribute path
93 94 95 |
# File 'lib/sprout/library.rb', line 93 def path @path end |
- (Object) pkg_name
Returns the value of attribute pkg_name
94 95 96 |
# File 'lib/sprout/library.rb', line 94 def pkg_name @pkg_name end |
- (Object) pkg_version
Returns the value of attribute pkg_version
95 96 97 |
# File 'lib/sprout/library.rb', line 95 def pkg_version @pkg_version end |
- (Object) platform
Returns the value of attribute platform
96 97 98 |
# File 'lib/sprout/library.rb', line 96 def platform @platform end |
Class Method Details
+ (Object) define_task(name = nil, pkg_name = nil, pkg_version = nil)
Create Rake tasks that will load and install a particular library into the current project.
This method is usually accessed from the global library helper.
library :asunit4
136 137 138 139 |
# File 'lib/sprout/library.rb', line 136 def define_task name=nil, pkg_name=nil, pkg_version=nil library = Sprout::Library.load name, pkg_name, pkg_version library.create_installation_tasks end |
+ (Object) project_path
The path within a project where libraries should be added.
Defaults to 'lib'
From anywhere in your Rakefile, you can output this value with:
puts ">> Library Project Path: #{Sprout::Library.project_path}"
123 124 125 |
# File 'lib/sprout/library.rb', line 123 def project_path @project_path ||= 'lib' end |
+ (Object) project_path=(path)
Set the path within a project where libraries should be loaded.
From top of your Rakefile, you can set this value with:
Sprout::Library.project_path = 'libs'
108 109 110 |
# File 'lib/sprout/library.rb', line 108 def project_path=(path) @project_path = path end |
Instance Method Details
- (Object) create_installation_tasks
Returns the outer Rake::Task which is invokable.
149 150 151 152 153 |
# File 'lib/sprout/library.rb', line 149 def create_installation_tasks define_lib_dir_task_if_necessary project_path create_project_tasks create_outer_task end |
- (Object) create_outer_task
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/sprout/library.rb', line 155 def create_outer_task t = task pkg_name # This helps executable rake tasks decide if they # want to do something special for library tasks. t.sprout_entity = self class << t def sprout_library? !sprout_entity.nil? && sprout_entity.is_a?(Sprout::Library) end end t end |