Class: MiniAether::Spec
- Inherits:
-
Object
- Object
- MiniAether::Spec
- Defined in:
- lib/mini_aether/spec.rb
Overview
A DSL to define and resolve dependencies. The Maven central repository is included by default.
Example:
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Class Method Summary collapse
Instance Method Summary collapse
-
#dep(dep_hash) ⇒ Object
Declare a dependency using an explicit hash of parameters.
-
#initialize(&block) ⇒ Spec
constructor
A new instance of Spec.
- #jar(coords) ⇒ Object
-
#require ⇒ Object
Resolve the dependencies using
MiniAether.resolve
and then require each of them (assumes each is a JAR file that may be required into JRuby). -
#resolve ⇒ Array<String>
Resolve the dependencies using
MiniAether.resolve
. -
#source(uri) ⇒ Object
Add a maven repository URL to the list of sources.
- #to_hash(coords) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Spec
Returns a new instance of Spec.
47 48 49 50 51 52 53 54 |
# File 'lib/mini_aether/spec.rb', line 47 def initialize(&block) @sources = [MAVEN_CENTRAL_REPO] @dependencies = [] if block_given? instance_eval &block end end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
43 44 45 |
# File 'lib/mini_aether/spec.rb', line 43 def dependencies @dependencies end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
45 46 47 |
# File 'lib/mini_aether/spec.rb', line 45 def group @group end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
43 44 45 |
# File 'lib/mini_aether/spec.rb', line 43 def sources @sources end |
Class Method Details
._attr(sym) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mini_aether/spec.rb', line 18 def _attr(sym) define_method(sym) do |*args, &block| value = if args && args.size > 0 args[0] else nil end iv = "@#{sym}".to_sym if value raise ArgumentError 'no effect without block' unless block orig = instance_variable_get iv instance_variable_set iv, value begin block.call ensure instance_variable_set iv, orig end else instance_variable_get iv end end end |
.attr(*syms) ⇒ Object
12 13 14 15 16 |
# File 'lib/mini_aether/spec.rb', line 12 def attr(*syms) syms.each do |sym| _attr(sym) end end |
Instance Method Details
#dep(dep_hash) ⇒ Object
Declare a dependency using an explicit hash of parameters.
68 69 70 |
# File 'lib/mini_aether/spec.rb', line 68 def dep(dep_hash) dependencies << dep_hash end |
#jar(coords) ⇒ Object
72 73 74 |
# File 'lib/mini_aether/spec.rb', line 72 def jar(coords) dependencies << to_hash(coords) end |
#require ⇒ Object
Resolve the dependencies using MiniAether.resolve
and then require each of them (assumes each is a JAR file that may be required into JRuby).
121 122 123 |
# File 'lib/mini_aether/spec.rb', line 121 def require resolve.each { |jar| Kernel.require jar } end |
#resolve ⇒ Array<String>
Resolve the dependencies using MiniAether.resolve
.
(likely jar files) satisfying the dependencies
114 115 116 |
# File 'lib/mini_aether/spec.rb', line 114 def resolve MiniAether.resolve(dependencies, sources) end |
#source(uri) ⇒ Object
Add a maven repository URL to the list of sources.
57 58 59 |
# File 'lib/mini_aether/spec.rb', line 57 def source(uri) sources << uri end |
#to_hash(coords) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mini_aether/spec.rb', line 76 def to_hash(coords) components = coords.split(':') case components.size when 1 { :group_id => group, :artifact_id => components[0], :version => version } when 2 if components[1] =~ /^\d/ { :group_id => group, :artifact_id => components[0], :version => components[1] } else { :group_id => components[0], :artifact_id => components[1], :version => version } end when 3 { :group_id => components[0], :artifact_id => components[1], :version => components[2] } else raise ArgumentError, "don't understand '#{coords}'" end end |