Class: Librarian::Dependency::Requirement
- Inherits:
-
Object
- Object
- Librarian::Dependency::Requirement
- Defined in:
- lib/librarian/puppet/extension.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Requirement
constructor
A new instance of Requirement.
-
#puppet_to_gem_version(version) ⇒ Object
convert Puppet versions to gem supported versions ‘1.x’ to ‘~>1.0’ ‘>=1.1.0 <2.0.0’ to [‘>=1.1.0’, ‘<2.0.0’] docs.puppetlabs.com/puppet/2.7/reference/modules_publishing.html.
- #puppet_to_gem_versions(args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Requirement
Returns a new instance of Requirement.
14 15 16 17 |
# File 'lib/librarian/puppet/extension.rb', line 14 def initialize(*args) args = initialize_normalize_args(args) self.backing = Gem::Requirement.create(puppet_to_gem_versions(args)) end |
Instance Method Details
#puppet_to_gem_version(version) ⇒ Object
convert Puppet versions to gem supported versions ‘1.x’ to ‘~>1.0’ ‘>=1.1.0 <2.0.0’ to [‘>=1.1.0’, ‘<2.0.0’] docs.puppetlabs.com/puppet/2.7/reference/modules_publishing.html
38 39 40 41 42 43 44 |
# File 'lib/librarian/puppet/extension.rb', line 38 def puppet_to_gem_version(version) constraints = version.scan(/([~<>=]*[ ]*[\d\.x]+)/).flatten # split the constraints constraints.map do |constraint| matched = /(.*)\.x/.match(constraint) matched.nil? ? constraint : "~>#{matched[1]}.0" end end |
#puppet_to_gem_versions(args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/librarian/puppet/extension.rb', line 19 def puppet_to_gem_versions(args) args.map do |arg| case arg when Array arg.map { |v| puppet_to_gem_version(v) } when String puppet_to_gem_version(arg) else # Gem::Requirement, convert to string (ie. =1.0) so we can concat later # Gem::Requirements can not be concatenated arg.requirements.map{|x,y| "#{x}#{y}"} end end.flatten end |