topaz 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -0
- data/Rakefile +24 -0
- data/lib/topaz.rb +172 -0
- data/topaz.gemspec +21 -0
- metadata +56 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 Hans Engel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2008 Hans Engel
|
3
|
+
See the file LICENSE for licensing details.
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
Gem.manage_gems
|
8
|
+
require 'rake/gempackagetask'
|
9
|
+
|
10
|
+
spec = eval( File.read('topaz.gemspec') )
|
11
|
+
|
12
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
13
|
+
pkg.need_tar = true
|
14
|
+
end
|
15
|
+
|
16
|
+
target = "pkg/#{spec.name}-#{spec.version}.gem"
|
17
|
+
|
18
|
+
task :default => target do
|
19
|
+
puts "generated latest version"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :bni => target do
|
23
|
+
puts `sudo gem install #{target}`
|
24
|
+
end
|
data/lib/topaz.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2008 Hans Engel
|
3
|
+
See the file LICENSE for licensing details.
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
module Topaz
|
9
|
+
class Contents
|
10
|
+
class << self
|
11
|
+
# Lists all files associated with a gem.
|
12
|
+
def contents(gem, version = '> 0.0.0')
|
13
|
+
s = Gem::SourceIndex.installed_spec_directories
|
14
|
+
spec = Gem::SourceIndex.from_gems_in(*s).search(gem, version).last
|
15
|
+
raise 'Gem provided could not be found' unless spec
|
16
|
+
files = []
|
17
|
+
spec.files.each do |f|
|
18
|
+
files.push File.join(spec.full_gem_path, f)
|
19
|
+
end
|
20
|
+
files
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Dependency
|
26
|
+
class << self
|
27
|
+
# Finds dependencies for a gem. Restrict by version with the `version`
|
28
|
+
# parameter. If `ret == :gem`, then an array of `Gem::Dependency` objects
|
29
|
+
# will be returned. If `ret == :raw`, then an array of arrays will be
|
30
|
+
# returned. Each array will have three elements: the name of the gem,
|
31
|
+
# its relation to the requirement `>=`, `<`, etc., and the version
|
32
|
+
# required (`0.4.1`, et al.)
|
33
|
+
def dependency(gem, version = '> 0.0.0', ret = :gem)
|
34
|
+
dependencies = []
|
35
|
+
source_index = Gem::SourceIndex.from_installed_gems
|
36
|
+
speclist = source_index.search(gem, version)
|
37
|
+
speclist.each do |spec|
|
38
|
+
dependencies << spec.dependencies
|
39
|
+
end
|
40
|
+
case ret
|
41
|
+
when :gem
|
42
|
+
dependencies
|
43
|
+
when :raw
|
44
|
+
raw = []
|
45
|
+
dependencies.first.each do |d|
|
46
|
+
raw << [d.name, d.version_requirements.requirements[0][0], d.version_requirements.requirements[0][1].to_s]
|
47
|
+
end
|
48
|
+
raw
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Environment
|
55
|
+
class << self
|
56
|
+
# Describes the current RubyGems environment.
|
57
|
+
def environment
|
58
|
+
{
|
59
|
+
:gem_path => Gem.path,
|
60
|
+
:installation_directory => Gem.dir,
|
61
|
+
:package_version => Gem::RubyGemsPackageVersion,
|
62
|
+
:remote_sources => Gem.sources,
|
63
|
+
:version => Gem::RubyGemsVersion
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Install
|
70
|
+
class << self
|
71
|
+
# Installs a gem with the name of `gem`, and optionally with the version
|
72
|
+
# of `version`.
|
73
|
+
def install(gem, version = '> 0.0.0')
|
74
|
+
`sudo gem install "#{gem}" -v "#{version}"`
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class List
|
80
|
+
class << self
|
81
|
+
# Returns an array of RubyGems. Set the `type` parameter to `:local`,
|
82
|
+
# `:remote`, or `:both` to have local or remote gems listed, respectively.
|
83
|
+
def list(type = :local)
|
84
|
+
type = case type
|
85
|
+
when :local
|
86
|
+
'-l'
|
87
|
+
when :remote
|
88
|
+
'-r'
|
89
|
+
when :both
|
90
|
+
'-b'
|
91
|
+
end
|
92
|
+
if type == '-l'
|
93
|
+
gems = Gem::cache.search ''
|
94
|
+
list = []
|
95
|
+
gems.each do |g|
|
96
|
+
list << [g.name, g.version.to_s]
|
97
|
+
end
|
98
|
+
list
|
99
|
+
else
|
100
|
+
`gem list #{type}`.scan(/^(\w+) \(([\d\.]+)/)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class Sources
|
107
|
+
class << self
|
108
|
+
# Adds a source.
|
109
|
+
def add(url)
|
110
|
+
out = `gem sources -a "#{url}"`
|
111
|
+
if out =~ /(.+) is not a URI/
|
112
|
+
raise 'URL provided is not valid'
|
113
|
+
elsif out =~ /While executing gem \.\.\. \(Zlib::GzipFile::Error\)/
|
114
|
+
raise 'Failed to access RubyGem repository'
|
115
|
+
elsif out =~ /added to sources/
|
116
|
+
return true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns an array of sources.
|
121
|
+
def list
|
122
|
+
sources = `gem sources -l`.scan(/^.+/)
|
123
|
+
sources.delete('*** CURRENT SOURCES ***')
|
124
|
+
return sources
|
125
|
+
end
|
126
|
+
alias :sources :list
|
127
|
+
|
128
|
+
# Removes a source.
|
129
|
+
def remove(url)
|
130
|
+
out = `gem sources -r "#{url}"`
|
131
|
+
if out =~ /not present in cache/
|
132
|
+
raise 'Provided source is not in the cache'
|
133
|
+
elsif out =~ /removed from sources/
|
134
|
+
return true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Updates the source cache
|
139
|
+
def update
|
140
|
+
`gem sources -u`
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class Specification
|
146
|
+
class << self
|
147
|
+
# Retrieve a specification object for the gem `gem`. Optionally a version
|
148
|
+
# can be specified with `version`. Returns a Gem::Specification instance.
|
149
|
+
def specification(gem, version = '> 0.0.0')
|
150
|
+
spec = Gem::SourceIndex.from_installed_gems.search(gem, version).first
|
151
|
+
end
|
152
|
+
|
153
|
+
# Retrieves a gem with the name of `gem`, and optionally with the version
|
154
|
+
# of `version`.
|
155
|
+
def method_missing(id, *args)
|
156
|
+
return unless args.length == 2 or args.length == 1
|
157
|
+
args[1] ||= '> 0.0.0'
|
158
|
+
eval('specification(args[0], args[1]).' + id.to_s)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class Uninstall
|
164
|
+
class << self
|
165
|
+
# Uninstalls a gem with the name of `gem`, and optionally with the version
|
166
|
+
# of `version`.
|
167
|
+
def uninstall(gem, version = '> 0.0.0')
|
168
|
+
`sudo gem uninstall "#{gem}" -v "#{version}"`
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
data/topaz.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2008 Hans Engel
|
3
|
+
See the file LICENSE for licensing details.
|
4
|
+
=end
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.author = 'Hans Engel'
|
8
|
+
s.date = Time.now
|
9
|
+
s.email = 'spam.me@engel.uk.to'
|
10
|
+
s.files = [
|
11
|
+
'LICENSE',
|
12
|
+
'Rakefile',
|
13
|
+
'topaz.gemspec',
|
14
|
+
'lib/topaz.rb']
|
15
|
+
s.homepage = 'http://github.com/hans/topaz'
|
16
|
+
s.name = 'topaz'
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.summary = 'A library for manipulating RubyGems'
|
20
|
+
s.version = '1.0'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: topaz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hans Engel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: spam.me@engel.uk.to
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- LICENSE
|
26
|
+
- Rakefile
|
27
|
+
- topaz.gemspec
|
28
|
+
- lib/topaz.rb
|
29
|
+
has_rdoc: false
|
30
|
+
homepage: http://github.com/hans/topaz
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.2.0
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: A library for manipulating RubyGems
|
55
|
+
test_files: []
|
56
|
+
|