Module: Bones::Plugins::Gem::Syntax
- Defined in:
- lib/bones/plugins/gem.rb
Instance Method Summary collapse
-
#depend_on(name, *args) ⇒ Object
Adds the given gem name to the current project’s dependency list.
-
#source(url) ⇒ Object
Add the given ‘url` to the list of gem sources.
Instance Method Details
#depend_on(name, *args) ⇒ Object
Adds the given gem name to the current project’s dependency list. An optional gem version can be given. If omitted, the newest gem version will be used.
14 15 16 17 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/bones/plugins/gem.rb', line 14 def depend_on(name, *args) opts = Hash === args.last ? args.pop : {} version = args.first || opts[:version] development = opts.key?(:development) ? opts[:development] : opts.key?(:dev) ? opts[:dev] : false spec = nil if Gem::Specification.respond_to? :find_by_name begin spec = Gem::Specification.find_by_name(name) rescue Gem::LoadError end else spec = Gem.source_index.find_name(name).last end version = "~> #{spec.version.to_s}" if version.nil? and !spec.nil? dep = case version when nil; [name] when %r/^\d/; [name, "= #{version}"] else [name, version] end development ? ::Bones.config.gem.development_dependencies << dep : ::Bones.config.gem.dependencies << dep nil end |