ktlacaelel-gemi 0.1.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kazuyoshi tlacaelel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = gemi
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 kazuyoshi tlacaelel. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gemi"
8
+ gem.summary = %Q{Gemi Gem installer}
9
+ gem.description = %Q{Gemi Gem installer}
10
+ gem.email = "kazu.dev@gmail.com"
11
+ gem.homepage = "http://github.com/ktlacaelel/gemi"
12
+ gem.authors = ["kazuyoshi tlacaelel"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "gemi #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/bin/gemi ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'gemi'
5
+
6
+ def banner
7
+ abort '
8
+ No configuration file given!
9
+
10
+ TRY THIS!
11
+
12
+ $ cat gems.yml
13
+ gems:
14
+ - name: ruby-openid
15
+ version: 2.1.4
16
+ native: 0
17
+
18
+ $ sudo gemi gems.yml
19
+
20
+ '
21
+ end
22
+
23
+ abort banner unless ARGV.size == 1
24
+ abort banner if ARGV[0] == '-h'
25
+ configuration = Gemi::Configuration.new(ARGV[0].to_s)
26
+ Gemi::Installer.new(configuration.gems.collect { |gem| Gemi::Gem.new(gem) }).run!
data/gemi.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gemi}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kazuyoshi tlacaelel"]
12
+ s.date = %q{2009-09-11}
13
+ s.default_executable = %q{gemi}
14
+ s.description = %q{Gemi Gem installer}
15
+ s.email = %q{kazu.dev@gmail.com}
16
+ s.executables = ["gemi"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/gemi",
29
+ "gemi.gemspec",
30
+ "lib/configuration.rb",
31
+ "lib/gem.rb",
32
+ "lib/gemi.rb",
33
+ "lib/installer.rb",
34
+ "lib/invalid_configuration_error.rb",
35
+ "lib/invalid_gem_hash_error.rb",
36
+ "lib/uninstalable_error.rb",
37
+ "test/configuration_test.rb",
38
+ "test/data/empty.yml",
39
+ "test/data/hack.yml",
40
+ "test/data/valid.yml",
41
+ "test/gem_test.rb",
42
+ "test/installer_test.rb",
43
+ "test/test_helper.rb"
44
+ ]
45
+ s.homepage = %q{http://github.com/ktlacaelel/gemi}
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.3}
49
+ s.summary = %q{Gemi Gem installer}
50
+ s.test_files = [
51
+ "test/configuration_test.rb",
52
+ "test/gem_test.rb",
53
+ "test/installer_test.rb",
54
+ "test/test_helper.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
63
+ else
64
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
68
+ end
69
+ end
@@ -0,0 +1,24 @@
1
+ module Gemi
2
+
3
+ class Configuration
4
+
5
+ def initialize(yaml_file)
6
+ unless File.exist? yaml_file
7
+ raise InvalidConfigurationError.new('No configuration file found!')
8
+ end
9
+ @yaml_file = yaml_file
10
+ @configuration = YAML::load_file(yaml_file)
11
+ end
12
+
13
+ def valid?
14
+ return false if File.zero?(@yaml_file)
15
+ return false unless @configuration.keys.include? 'gems'
16
+ end
17
+
18
+ def gems
19
+ @configuration['gems']
20
+ end
21
+
22
+ end
23
+
24
+ end
data/lib/gem.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Gemi
2
+
3
+ class Gem
4
+
5
+ ERR_NOT_A_HASH = 'Failed to initialize hash not given?'
6
+ ERR_MISSING_KEY = 'Failed to initialize %s not given?'
7
+
8
+ attr_reader :version, :name
9
+
10
+ def initialize(gem_hash)
11
+ unless gem_hash.is_a? Hash
12
+ raise InvalidGemHashError.new(ERR_NOT_A_HASH)
13
+ end
14
+ @gem_hash = gem_hash
15
+ ['name', 'version', 'native'].each do |key|
16
+ unless has? key
17
+ raise InvalidGemHashError.new(ERR_MISSING_KEY % key)
18
+ end
19
+ end
20
+ @name = @gem_hash['name']
21
+ @version = @gem_hash['version']
22
+ @native = @gem_hash['native']
23
+ end
24
+
25
+ def native?
26
+ @gem_hash['native'] == 1
27
+ end
28
+
29
+ def has?(key)
30
+ @gem_hash.keys.include? key
31
+ end
32
+
33
+ end
34
+
35
+ end
data/lib/gemi.rb ADDED
@@ -0,0 +1,13 @@
1
+
2
+
3
+ # external libraries
4
+ require 'yaml'
5
+
6
+ # required libraries
7
+ require 'configuration'
8
+ require 'gem'
9
+ require 'installer'
10
+ require 'invalid_configuration_error'
11
+ require 'invalid_gem_hash_error'
12
+ require 'uninstalable_error'
13
+
data/lib/installer.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Gemi
2
+
3
+ class Installer
4
+
5
+ def initialize(array = [])
6
+ unless array.is_a? Array
7
+ raise UninstalableError.new('Not an array of gems')
8
+ end
9
+ @gems = []
10
+ array.each { |gem| add_gem(gem) }
11
+ end
12
+
13
+ def add_gem(new_gem)
14
+ unless new_gem.is_a? Gemi::Gem
15
+ raise UninstalableError.new('Only Gemi::Gem\'s are instalable')
16
+ end
17
+ @gems << new_gem
18
+ end
19
+
20
+ def count_gems
21
+ @gems.size
22
+ end
23
+
24
+ def run!
25
+ @gems.each do |gem|
26
+ if gem.native?
27
+ puts "Skipped #{gem.name} because of native extensions"
28
+ else
29
+ puts `gem install #{gem.name} --version #{gem.version}`
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,6 @@
1
+ module Gemi
2
+
3
+ class InvalidConfigurationError < Exception
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Gemi
2
+
3
+ class InvalidGemHashError < Exception
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Gemi
2
+
3
+ class UninstalableError < Exception
4
+ end
5
+
6
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @valid_file = 'test/data/valid.yml'
7
+ @empty_file = 'test/data/empty.yml'
8
+ @hack_file = 'test/data/hack.yml'
9
+ @invalid_file = 'xxxxxxxxxxxxxxxx.yml'
10
+ @gems = [{
11
+ 'name' => 'ruby-openid',
12
+ 'version' => '2.1.4',
13
+ 'native' => 0,
14
+ }]
15
+ end
16
+
17
+ should 'receive a yaml file in constructor' do
18
+ Gemi::Configuration.new(@valid_file)
19
+ end
20
+
21
+ should 'check for file existance' do
22
+ assert_raise(Gemi::InvalidConfigurationError) do
23
+ Gemi::Configuration.new(@invalid_file)
24
+ end
25
+ end
26
+
27
+ should 'not be valid if file is empty' do
28
+ assert_equal false, Gemi::Configuration.new(@empty_file).valid?
29
+ end
30
+
31
+ should 'load gems' do
32
+ assert_equal @gems, Gemi::Configuration.new(@valid_file).gems
33
+ end
34
+
35
+ should 'properly validate hacked file!' do
36
+ assert_equal false, Gemi::Configuration.new(@hack_file).valid?
37
+ end
38
+
39
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ hack:
2
+ - name: ruby-openid
3
+ version: 2.1.4
4
+ native: 0
@@ -0,0 +1,5 @@
1
+
2
+ gems:
3
+ - name: ruby-openid
4
+ version: 2.1.4
5
+ native: 0
data/test/gem_test.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+
3
+ class GemTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @valid = {
7
+ 'name' => 'ruby-openid',
8
+ 'version' => '2.1.4',
9
+ 'native' => 0,
10
+ }
11
+ @no_name = {
12
+ 'version' => '2.1.4',
13
+ 'native' => 0,
14
+ }
15
+ @no_version = {
16
+ 'name' => 'ruby-openid',
17
+ 'native' => 0,
18
+ }
19
+ @no_native = {
20
+ 'name' => 'ruby-openid',
21
+ 'version' => '2.1.4',
22
+ }
23
+ end
24
+
25
+ #=============================================================================
26
+ # INSTANTIATION
27
+ #=============================================================================
28
+
29
+ should 'load a gem hash on initialization' do
30
+ Gemi::Gem.new(@valid)
31
+ end
32
+
33
+ should 'not load if name is not given' do
34
+ assert_raise(Gemi::InvalidGemHashError) do
35
+ Gemi::Gem.new(@no_name)
36
+ end
37
+ end
38
+
39
+ should 'not load if version is not given' do
40
+ assert_raise(Gemi::InvalidGemHashError) do
41
+ Gemi::Gem.new(@no_version)
42
+ end
43
+ end
44
+
45
+ should 'not load if native is not given' do
46
+ assert_raise(Gemi::InvalidGemHashError) do
47
+ Gemi::Gem.new(@no_native)
48
+ end
49
+ end
50
+
51
+ #=============================================================================
52
+ # DATA RETRIVAL
53
+ #=============================================================================
54
+
55
+ should 'retrive gem name' do
56
+ assert_equal 'ruby-openid', Gemi::Gem.new(@valid).name
57
+ end
58
+
59
+ should 'retrive gem version' do
60
+ assert_equal '2.1.4', Gemi::Gem.new(@valid).version
61
+ end
62
+
63
+ should 'tell if gem has native extensions' do
64
+ assert_equal false, Gemi::Gem.new(@valid).native?
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ class InstallerTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @hash_one = {
7
+ 'name' => 'ruby-openid',
8
+ 'version' => '2.1.4',
9
+ 'native' => 0,
10
+ }
11
+ @hash_two = {
12
+ 'name' => 'xxxxxxxxxxx',
13
+ 'version' => '2.1.4',
14
+ 'native' => 0,
15
+ }
16
+ @gem_one = Gemi::Gem.new(@hash_one)
17
+ @gem_two = Gemi::Gem.new(@hash_two)
18
+ end
19
+
20
+ should 'not initialize when no array is given to constructor' do
21
+ assert_raise (Gemi::UninstalableError) do
22
+ Gemi::Installer.new(nil)
23
+ end
24
+ assert_raise (Gemi::UninstalableError) do
25
+ Gemi::Installer.new(false)
26
+ end
27
+ end
28
+
29
+ should 'accept an empty array on initialization' do
30
+ Gemi::Installer.new([])
31
+ end
32
+
33
+ should 'initialize with no arguments at all' do
34
+ Gemi::Installer.new
35
+ end
36
+
37
+ should 'validate gems on initialization' do
38
+ assert_raise (Gemi::UninstalableError) do
39
+ Gemi::Installer.new([@gem_one, 2])
40
+ end
41
+ end
42
+
43
+ should 'should append gems' do
44
+ installer = Gemi::Installer.new([@gem_one])
45
+ installer.add_gem(@gem_two)
46
+ assert_equal 2, installer.count_gems
47
+ end
48
+
49
+ should 'should validate when appending gems' do
50
+ installer = Gemi::Installer.new
51
+ assert_raise (Gemi::UninstalableError) do
52
+ installer.add_gem(1)
53
+ end
54
+ end
55
+
56
+ should 'should install a gem when runned'
57
+
58
+ end
59
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'gemi'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ktlacaelel-gemi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - kazuyoshi tlacaelel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-11 00:00:00 -07:00
13
+ default_executable: gemi
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Gemi Gem installer
26
+ email: kazu.dev@gmail.com
27
+ executables:
28
+ - gemi
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/gemi
42
+ - gemi.gemspec
43
+ - lib/configuration.rb
44
+ - lib/gem.rb
45
+ - lib/gemi.rb
46
+ - lib/installer.rb
47
+ - lib/invalid_configuration_error.rb
48
+ - lib/invalid_gem_hash_error.rb
49
+ - lib/uninstalable_error.rb
50
+ - test/configuration_test.rb
51
+ - test/data/empty.yml
52
+ - test/data/hack.yml
53
+ - test/data/valid.yml
54
+ - test/gem_test.rb
55
+ - test/installer_test.rb
56
+ - test/test_helper.rb
57
+ has_rdoc: false
58
+ homepage: http://github.com/ktlacaelel/gemi
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.2.0
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Gemi Gem installer
83
+ test_files:
84
+ - test/configuration_test.rb
85
+ - test/gem_test.rb
86
+ - test/installer_test.rb
87
+ - test/test_helper.rb