haddock 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,27 +56,20 @@ Or:
56
56
 
57
57
  == INSTALL
58
58
 
59
- RubyForge:
60
-
61
- % gem install haddock
62
-
63
-
64
- GitHub:
65
-
66
- % gem install stephencelis-haddock --source=http://gems.github.com
59
+ % [sudo] gem install haddock
67
60
 
68
61
 
69
62
  == LICENSE
70
63
 
71
64
  (The MIT License)
72
65
 
73
- (c) 2009-* Stephen Celis, stephen@stephencelis.com.
66
+ (c) 2009-2010 Stephen Celis, stephen@stephencelis.com.
74
67
 
75
- Permission is hereby granted, free of charge, to any person obtaining a copy
76
- of this software and associated documentation files (the "Software"), to deal
77
- in the Software without restriction, including without limitation the rights
78
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
79
- copies of the Software, and to permit persons to whom the Software is
68
+ Permission is hereby granted, free of charge, to any person obtaining a copy
69
+ of this software and associated documentation files (the "Software"), to deal
70
+ in the Software without restriction, including without limitation the rights
71
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
72
+ copies of the Software, and to permit persons to whom the Software is
80
73
  furnished to do so, subject to the following conditions:
81
74
 
82
75
  The above copyright notice and this permission notice shall be included in all
data/Rakefile CHANGED
@@ -1,11 +1,16 @@
1
1
  $: << File.dirname(__FILE__) + "/lib"
2
2
  require "rubygems"
3
- require "hoe"
4
3
  require "haddock"
5
4
 
6
- Hoe.new('haddock', Haddock::VERSION) do |p|
7
- p.developer('Stephen Celis', 'stephen@stephencelis.com')
8
- p.remote_rdoc_dir = ''
9
- p.readme_file = "README.rdoc"
10
- p.history_file = "History.rdoc"
5
+ require "rake/testtask"
6
+
7
+ desc "Default: run unit tests."
8
+ task :default => :test
9
+
10
+ desc "Run unit tests."
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/test_*.rb'
15
+ t.verbose = true
11
16
  end
data/bin/ha-gen CHANGED
@@ -5,7 +5,7 @@ require "optparse"
5
5
  require "haddock"
6
6
  include Haddock
7
7
 
8
- parser = OptionParser.new do |opts|
8
+ OptionParser.new do |opts|
9
9
  opts.banner = "usage: #{File.basename($0)} [options]"
10
10
 
11
11
  opts.on("-V", "--version") do
@@ -18,27 +18,30 @@ parser = OptionParser.new do |opts|
18
18
  exit
19
19
  end
20
20
 
21
- opts.on("-l", "--length [length]") do |value|
22
- raise Password::LengthError, "Invalid length" if value.match(/\D/)
23
- @length = value.to_i
21
+ opts.on("-l", "--length [length]", Integer) do |value|
22
+ @length = value
24
23
  end
25
24
 
26
25
  opts.on("-f", "--words [words file]") do |value|
27
26
  Password.diction = value
28
27
  end
29
- end
30
28
 
31
- begin
32
- parser.parse!
33
- puts @length ? Password.generate(@length) : Password.generate
34
- rescue OptionParser::ParseError, Password::LengthError => error
35
- warn "#{File.basename($0)}: #{error.message} " +
36
- "(must be between #{Password::MINIMUM} and #{Password::MAXIMUM})."
37
- puts parser
38
- exit 1
39
- rescue Password::NoWordsError => error
40
- warn "#{File.basename($0)}: #{error.message}."
41
- puts "Word lists are available here: http://wordlist.sourceforge.net"
42
- puts parser
43
- exit 1
29
+ opts.on("-d", "--delimiters [symbols]") do |value|
30
+ Password.delimiters = value
31
+ end
32
+
33
+ begin
34
+ opts.parse!
35
+ puts @length ? Password.generate(@length) : Password.generate
36
+ rescue OptionParser::ParseError, Password::LengthError => error
37
+ warn "#{File.basename($0)}: #{error.message} " +
38
+ "(must be between #{Password::MINIMUM} and #{Password::MAXIMUM})."
39
+ puts opts
40
+ abort
41
+ rescue Password::NoWordsError => error
42
+ warn "#{File.basename($0)}: #{error.message}."
43
+ puts "Word lists are available here: http://wordlist.sourceforge.net"
44
+ puts opts
45
+ abort
46
+ end
44
47
  end
@@ -1,18 +1,24 @@
1
1
  # A more memorable password generator. Swordfish? No, I got tired of that. I
2
2
  # changed it.
3
3
  module Haddock
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
 
6
6
  module Password
7
+ # The minimum password legnth.
7
8
  MINIMUM = 8
9
+
10
+ # The maximum password length.
8
11
  MAXIMUM = 31
12
+
13
+ # The default password length.
9
14
  DEFAULT = 12
10
15
 
11
- SYMBOLS = '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'
16
+ # Paths used to detect default words files.
17
+ PATHS = %w(/usr/share/dict/words /usr/share/words)
12
18
 
13
- class << self
14
- @@paths = %w(/usr/share/dict/words /usr/share/words)
19
+ @@delimiters = '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'
15
20
 
21
+ class << self
16
22
  # Generates a more memorable password. Its one optional argument
17
23
  # determines the length of the generated password, and cannot be less
18
24
  # than 8 or greater than 31 characters (default: 12).
@@ -22,7 +28,7 @@ module Haddock
22
28
  # Password.generate(8) # => "amy7@rax"
23
29
  def generate(length = DEFAULT)
24
30
  unless defined? @@diction
25
- self.diction = @@paths.find { |path| File.exist? path }
31
+ self.diction = PATHS.find { |path| File.exist? path }
26
32
  end
27
33
 
28
34
  raise LengthError, "Invalid length" unless length.is_a? Integer
@@ -32,7 +38,7 @@ module Haddock
32
38
  words_limit = length * 0.75 # Ensure over-proportionate word lengths.
33
39
 
34
40
  begin
35
- words = %W(#{random_word} #{random_symbol}#{random_word})
41
+ words = %W(#{random_word} #{random_delimiter}#{random_word})
36
42
  words_length = words.join.length
37
43
  end until words_length < length && words_length > words_limit
38
44
 
@@ -51,14 +57,21 @@ module Haddock
51
57
  raise NoWordsError, "No words file at #{path.inspect}"
52
58
  end
53
59
 
60
+ # Sets the list of characters that can delimit words. Default:
61
+ #
62
+ # `~!@#$%^&*()-_=+[{]}\|;:'",<.>/?
63
+ def delimiters=(string)
64
+ @@delimiters = string
65
+ end
66
+
54
67
  private
55
68
 
56
69
  def random_word
57
70
  @@diction[rand(@@diction.length)].chomp
58
71
  end
59
72
 
60
- def random_symbol
61
- SYMBOLS[rand(SYMBOLS.length), 1]
73
+ def random_delimiter
74
+ @@delimiters[rand(@@delimiters.length), 1]
62
75
  end
63
76
 
64
77
  def random_number(digits)
@@ -11,7 +11,8 @@ class TestHaddock < Test::Unit::TestCase
11
11
  end
12
12
 
13
13
  def test_password_format
14
- symbols = "[#{Regexp.quote Password::SYMBOLS}]"
14
+ symbols = Password.send :class_variable_get, :@@delimiters
15
+ symbols = "[#{Regexp.quote symbols}]"
15
16
  pattern = /^[a-z]+[0-9]+#{symbols}{1}[a-z]+/i
16
17
  assert_match(pattern, Password.generate)
17
18
  end
@@ -28,6 +29,11 @@ class TestHaddock < Test::Unit::TestCase
28
29
  Password.diction = "/usr/share/dict/words"
29
30
  end
30
31
 
32
+ def test_accepts_alternate_symbols_list
33
+ Password.delimiters = "!"
34
+ assert_equal "!", Password.send(:random_delimiter)
35
+ end
36
+
31
37
  def test_fail_on_too_short
32
38
  assert_raise Password::LengthError do
33
39
  Password.generate(Password::MINIMUM - 1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haddock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Celis
@@ -9,24 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-14 00:00:00 -05:00
12
+ date: 2010-01-04 00:00:00 -06:00
13
13
  default_executable: ha-gen
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: hoe
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.12.2
24
- version:
25
- description: |-
26
- A more memorable password generator. Swordfish? No, I got tired of that. I
27
- changed it.
28
- email:
29
- - stephen@stephencelis.com
14
+ dependencies: []
15
+
16
+ description: A more memorable password generator. Swordfish? No, I got tired of that. I changed it.
17
+ email: stephen@stephencelis.com
30
18
  executables:
31
19
  - ha-gen
32
20
  extensions: []