pairest 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43ca17bb49abd0d143b988bcb99fa710804a25e8
4
+ data.tar.gz: 8c7774b0b5455cd19ecba301ddbc2045d8046723
5
+ SHA512:
6
+ metadata.gz: 983b029eb8bd829a7bf90ea8509c085d65967aa0487eba1c1d0e77b250c55e2022717752d4c8a418fe12e3036cd4da1041a7e40915824b80d9319884dd35abd8
7
+ data.tar.gz: d2508a7171936a7bd4db415164852c45bbd4bd438d3af72eb6edb7cd7ecbf8d6343eaeaae93ff15c0cc069d21013efe855f415fd1e728ff0389851808a157ad4
data/bin/pairest ADDED
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ require 'pairest'
3
+ Pairest.main(ARGV)
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ class ConfigurationProvider
4
+ def self.user_configurations
5
+ yaml_users = load_yaml
6
+
7
+ yaml_users.map do |initials, details|
8
+ UserConfiguration.new initials: initials,
9
+ name: details['name'],
10
+ key: details['key_name'],
11
+ email: details['email']
12
+ end
13
+ end
14
+
15
+ private_class_method
16
+
17
+ def self.load_yaml
18
+ full_config_path = File.expand_path('~/.pairest.yml')
19
+
20
+ if File.exist? full_config_path
21
+ config_file = File.read(full_config_path)
22
+ YAML.load(config_file)
23
+ else
24
+ File.write(full_config_path, skeleton_pairest_config)
25
+ puts 'Creating ~/.pairest.yml for you. Edit it before you continue'
26
+ raise SystemExit
27
+ end
28
+ end
29
+
30
+ def self.skeleton_pairest_config
31
+ "hp:\n" \
32
+ " name: Haskell Pointer\n" \
33
+ " email: kyle.pointer@asynchrony.com\n" \
34
+ " key_name: kyle.pointer\n" \
35
+ "eu:\n" \
36
+ " name: Example User\n" \
37
+ " email: example.user@somewhere.com\n" \
38
+ " key_name: example.user\n"
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ class GitConfigurator
2
+ def self.write_name_setting(name_string)
3
+ system "git config user.name \"#{name_string}\""
4
+ end
5
+
6
+ def self.write_email_settings(email_string)
7
+ system "git config user.email \"#{email_string}\""
8
+ end
9
+ end
data/lib/pairest.rb ADDED
@@ -0,0 +1,53 @@
1
+ require_relative 'configuration_provider'
2
+ require_relative 'git_configurator'
3
+ require_relative 'ssh_configurator'
4
+ require_relative 'user_configuration'
5
+
6
+ class Pairest
7
+ def self.main(initials)
8
+ validate_input(initials)
9
+
10
+ GitConfigurator.write_name_setting names(initials)
11
+ GitConfigurator.write_email_settings emails(initials)
12
+ SshConfigurator.link_current_key key(initials)
13
+ end
14
+
15
+ private_class_method
16
+
17
+ def self.validate_input(initials)
18
+ usage_message = "Usage: pairest [initials] [initials]\n" \
19
+ "Example: pairest hp ko\n" \
20
+ " pairest hp\n" \
21
+ " pairest hp ko bl\n"
22
+
23
+ if initials.empty?
24
+ puts usage_message
25
+ raise SystemExit
26
+ end
27
+ end
28
+
29
+ def self.configs(initials)
30
+ @configs ||= ConfigurationProvider.user_configurations
31
+
32
+ initials.map do |initial|
33
+ user_config = @configs.find { |config| config.initials == initial }
34
+ unless user_config
35
+ raise "Unknown initials: #{initial}. Add #{initial} to ~/.pairest.yml"
36
+ end
37
+ user_config
38
+ end
39
+ end
40
+
41
+ def self.key(initials)
42
+ first_config = configs(initials).first
43
+ first_config.key
44
+ end
45
+
46
+ def self.names(initials)
47
+ configs(initials).map(&:name).join(', ')
48
+ end
49
+
50
+ def self.emails(initials)
51
+ configs(initials).map(&:email).join(', ')
52
+ end
53
+ end
@@ -0,0 +1,39 @@
1
+ require 'fileutils'
2
+
3
+ class SshConfigurator
4
+ def self.link_current_key(name)
5
+ verify_ssh_config_exists
6
+
7
+ FileUtils.ln_sf(
8
+ File.expand_path("~/.ssh/#{name}"),
9
+ File.expand_path('~/.ssh/current_key')
10
+ )
11
+ end
12
+
13
+ private_class_method
14
+
15
+ def self.verify_ssh_config_exists
16
+ full_config_path = File.expand_path('~/.ssh/config')
17
+
18
+ unless File.exist? full_config_path
19
+ File.write(full_config_path, skeleton_ssh_config)
20
+ puts error_message
21
+ raise SystemExit
22
+ end
23
+ end
24
+
25
+ def self.error_message
26
+ "Creating ~/.ssh/config for you.\n" \
27
+ "Please edit it before you continue.\n" \
28
+ "Pairest will manage a symbolic link called\n" \
29
+ "current_key in ~/.ssh, so you probably want to\n" \
30
+ "keep that part of the ssh config the same.\n"
31
+ end
32
+
33
+ def self.skeleton_ssh_config
34
+ "Host dev.example.com\n" \
35
+ " HostName dev.example.com\n" \
36
+ " User git\n" \
37
+ " IdentityFile ~/.ssh/current_key\n"
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ class UserConfiguration
2
+ attr_reader :name, :email, :key, :initials
3
+
4
+ def initialize(name: nil, email: nil, key: nil, initials: nil)
5
+ @name = name
6
+ @email = email
7
+ @key = key
8
+ @initials = initials
9
+
10
+ raise 'User Information Missing' unless everything_defined?
11
+ end
12
+
13
+ def ==(other)
14
+ state_variables == other.state_variables
15
+ end
16
+
17
+ private
18
+
19
+ def everything_defined?
20
+ [name, email, key, initials].all? do |attribute|
21
+ attribute.class == String && !attribute.empty?
22
+ end
23
+ end
24
+
25
+ protected
26
+
27
+ def state_variables
28
+ [name, email, key, initials]
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pairest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Haskell Pointer
8
+ - Brian Lai
9
+ - Kali Olsen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-09-06 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Have you ever wanted a git pair utility but also care about your SSH
16
+ keys? Then Pairest might be for you. Maybe.
17
+ email: haskell.pointer@asynchrony.com
18
+ executables:
19
+ - pairest
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/pairest
24
+ - lib/configuration_provider.rb
25
+ - lib/git_configurator.rb
26
+ - lib/pairest.rb
27
+ - lib/ssh_configurator.rb
28
+ - lib/user_configuration.rb
29
+ homepage: https://github.com/glaukommatos/pairest
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.4.5.1
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Pairest is a pair switching utility for Git written in Ruby!
53
+ test_files: []