rumm 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97357391b81a9c9f37e2580228e2009b11d64df4
4
- data.tar.gz: 8b0dd6acd5dd5a33674d4f41705296dcd6fa29d7
3
+ metadata.gz: cc24108bd8cdec93e429a103d5c862b94c6d1039
4
+ data.tar.gz: f9effd84d6c5826a06c2eb03abafe04da5c91918
5
5
  SHA512:
6
- metadata.gz: a509e66c8057eb5fa97117d30b02c5dd425a4ebec5cd1b3cedbe49af07f0f7c3e2828e84ad8100d79ce3ef15cb55f9f5494c5cb0f0944cd5873c1958a37e40c4
7
- data.tar.gz: fd7042e235e672fb6da464918585bf6b19424ab6203d2c6ad289b7171f2cb85685c99f1f376bad637ef579a4803cc85222994d6510588136f0505b0eebcf1c62
6
+ metadata.gz: a86d6cb0234bff1c0622330b924b7c86f7226037ad29b613f077844ae2537755e3c42e39c179082b5b8799a5f7abf0b4d8c566f71a6cbbcb6beed4e88d75eac5
7
+ data.tar.gz: 480d7bde974beeb5b16170846ef7fbe8bccc4e64ce5ae030c2ae63f4260997216b37f97ac391a9fb859c741f3eaa8c7f0ed88d7b00b2187aa33500dda78c468b
data/README.md CHANGED
@@ -22,7 +22,7 @@ Authenticate with rackspace
22
22
  Now we can see the list of servers we have available:
23
23
 
24
24
  $ rumm show servers
25
- you don't have any servers, but you can create on with:
25
+ you don't have any servers, but you can create one by running:
26
26
  rumm create server
27
27
 
28
28
  Create the server:
data/Rakefile CHANGED
@@ -4,3 +4,30 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+
8
+ desc "build the list of names and pack it into a pstore"
9
+ task "names:build" do
10
+ require "pstore"
11
+ adjective_file = File.expand_path "../app/providers/naming/adj.txt", __FILE__
12
+ noun_file = File.expand_path "../app/providers/naming/nouns.txt", __FILE__
13
+ PStore.new(File.expand_path("../app/providers/naming/dictionary.pstore", __FILE__)).tap do |store|
14
+ store.transaction do
15
+ adjectives = store["adjectives"] = {}
16
+ File.open(adjective_file) do |file|
17
+ file.each_line do |line|
18
+ first_letter = line[0]
19
+ adjectives[first_letter] ||= []
20
+ adjectives[first_letter] << line.chomp
21
+ end
22
+ end
23
+ nouns = store["nouns"] = {}
24
+ File.open(noun_file) do |file|
25
+ file.each_line do |line|
26
+ first_letter = line[0]
27
+ nouns[first_letter] ||= []
28
+ nouns[first_letter] << line.chomp
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,106 +1,37 @@
1
+ require "pstore"
2
+
1
3
  class NamingProvider
2
4
 
3
5
  def value
4
6
  self
5
7
  end
6
8
 
7
- def generate_name adj, noun
8
- if adj == nil and noun == nil
9
- get_adj + "-" + get_noun
10
- else
11
- get_adj_bound(adj) + "-" + get_noun_bound(noun)
12
- end
9
+ def generate_name(first_letter = random_letter, last_letter = random_letter)
10
+ "#{adjective first_letter}-#{noun last_letter}"
11
+ end
12
+
13
+ def random_letter
14
+ ('a'..'z').to_a.shuffle.first
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def get_adj
18
- a = rand(20748)
19
- counter = 0
20
- dict = File.new(File.expand_path "../naming/adj.txt", __FILE__)
21
- dict.each_line do |line|
22
- if counter == a
23
- return line.delete("\n")
24
- end
25
- counter+=1
26
- end
19
+ def dictionary(key)
20
+ @dictionary ||= PStore.new dictionary_file
21
+ @dictionary.transaction(true) { @dictionary[key] }
27
22
  end
28
23
 
29
- def get_noun
30
- a = rand(50432)
31
- counter = 0
32
- dict = File.new(File.expand_path "../naming/nouns.txt", __FILE__)
33
- dict.each_line do |line|
34
- if counter == a
35
- return line.delete("\n")
36
- end
37
- counter+=1
38
- end
24
+ def dictionary_file
25
+ File.expand_path '../naming/dictionary.pstore', __FILE__
39
26
  end
40
27
 
41
- def get_adj_bound letter
42
- higher = true
43
- upper = 20748
44
- lower = 0
45
- a = 0
46
- word = ""
47
- done = false
48
- until done
49
- if higher
50
- lower = a
51
- else
52
- upper = a
53
- end
54
- a = rand lower..upper
55
- counter = 0
56
- dict = File.new(File.expand_path "../naming/adj.txt", __FILE__)
57
- dict.each_line do |line|
58
- if counter == a
59
- word = line.delete("\n")
60
- break
61
- end
62
- counter+=1
63
- end
64
- if word[0] == letter
65
- return word
66
- elsif word[0] <= letter
67
- higher = true
68
- else
69
- higher = false
70
- end
71
- end
28
+ def noun(first_letter)
29
+ list = dictionary('nouns')[first_letter]
30
+ list[rand(list.length - 1)]
72
31
  end
73
32
 
74
- def get_noun_bound letter
75
- higher = true
76
- upper = 50432
77
- lower = 0
78
- a = 0
79
- word = ""
80
- done = false
81
- until done
82
- if higher
83
- lower = a
84
- else
85
- upper = a
86
- end
87
- a = rand lower..upper
88
- counter = 0
89
- dict = File.new(File.expand_path "../naming/nouns.txt", __FILE__)
90
- dict.each_line do |line|
91
- if counter == a
92
- word = line.delete("\n")
93
- break
94
- end
95
- counter+=1
96
- end
97
- if word[0] == letter
98
- return word
99
- elsif word[0] <= letter
100
- higher = true
101
- else
102
- higher = false
103
- end
104
- end
33
+ def adjective(first_letter)
34
+ list = dictionary('adjectives')[first_letter]
35
+ list[rand(list.length - 1)]
105
36
  end
106
37
  end
data/lib/rumm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rumm
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require "naming_provider"
3
+
4
+ describe "fancy naming" do
5
+ use_natural_assertions
6
+ Given(:name) { NamingProvider.new.generate_name *arguments }
7
+
8
+ context "with no arguments" do
9
+ Given(:arguments) { [] }
10
+ Then { not name.nil? }
11
+ Then { name.length > 1}
12
+ end
13
+ context "with a first letter and last letter" do
14
+ Given(:parts) { name.split '-' }
15
+ context "with different letters" do
16
+ Given(:arguments) { ['f', 'b'] }
17
+ Then { parts.first[0] == 'f' }
18
+ Then { parts.last[0] == 'b' }
19
+ end
20
+ context "with the same letter" do
21
+ Given(:arguments) { ['s', 's'] }
22
+ Then { parts.first[0] == 's'}
23
+ Then { parts.last[0] == 's' }
24
+ end
25
+ end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require "rumm"
2
2
  require "vcr"
3
3
  require "aruba/api"
4
4
  require "rspec-given"
5
+ $: << File.expand_path("../../app/providers", __FILE__)
5
6
 
6
7
  module Rumm::SpecHelper
7
8
  def will_type(string)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -29,7 +29,7 @@ cert_chain:
29
29
  UgImJlChAzCoDP9zi9tdm6jAr7ttF25R9PPYr11ILb7dYe3qUzlNlM6zJx/nb31b
30
30
  IhdyRVup4qLcqYSTPsm6u7VA
31
31
  -----END CERTIFICATE-----
32
- date: 2013-07-20 00:00:00.000000000 Z
32
+ date: 2013-07-22 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: mvcli
@@ -160,6 +160,7 @@ files:
160
160
  - app/providers/instances_provider.rb
161
161
  - app/providers/loadbalancers_provider.rb
162
162
  - app/providers/naming/adj.txt
163
+ - app/providers/naming/dictionary.pstore
163
164
  - app/providers/naming/nouns.txt
164
165
  - app/providers/naming_provider.rb
165
166
  - app/providers/nodes_provider.rb
@@ -223,6 +224,7 @@ files:
223
224
  - spec/fixtures/cassettes/show-servers.yml
224
225
  - spec/fixtures/cassettes/successful-login.yml
225
226
  - spec/fixtures/cassettes/unsuccessful-login.yml
227
+ - spec/providers/naming_provider_spec.rb
226
228
  - spec/spec_helper.rb
227
229
  - tmp/aruba/.gitkeep
228
230
  homepage: https://github.com/rackerlabs/rumm
@@ -259,5 +261,6 @@ test_files:
259
261
  - spec/fixtures/cassettes/show-servers.yml
260
262
  - spec/fixtures/cassettes/successful-login.yml
261
263
  - spec/fixtures/cassettes/unsuccessful-login.yml
264
+ - spec/providers/naming_provider_spec.rb
262
265
  - spec/spec_helper.rb
263
266
  has_rdoc: