shiritori 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +3 -0
- data/.travis.yml +2 -0
- data/Rakefile +5 -0
- data/bin/shiritori +9 -1
- data/lib/shiritori.rb +0 -2
- data/lib/shiritori/cli.rb +2 -4
- data/lib/shiritori/convert.rb +5 -5
- data/lib/shiritori/search_method.rb +3 -13
- data/lib/shiritori/shiritori.rb +6 -6
- data/lib/shiritori/version.rb +1 -1
- data/lib/shiritori/view.rb +1 -1
- data/shiritori.gemspec +1 -4
- data/spec/shiritori/basic_object_method_spec.rb +0 -2
- data/spec/shiritori/bignum_method_spec.rb +0 -2
- data/spec/shiritori/enumerator_method_spec.rb +0 -2
- data/spec/shiritori/false_method_spec.rb +0 -2
- data/spec/shiritori/fixnum_method_spec.rb +0 -2
- data/spec/shiritori/nil_method_spec.rb +0 -2
- data/spec/shiritori/random_method_spec.rb +0 -2
- data/spec/shiritori/range_method_spec.rb +0 -2
- data/spec/shiritori/shiritori_spec.rb +11 -1
- data/spec/shiritori/string_method_spec.rb +0 -2
- data/spec/shiritori/symbol_method_spec.rb +0 -2
- data/spec/shiritori/true_method_spec.rb +0 -2
- data/spec/spec_helper.rb +11 -3
- metadata +5 -47
- data/Guardfile +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d232b530daf6a056a86f3ae98b296b8b3bc58c
|
4
|
+
data.tar.gz: b5814ea22d52b5b8325c54ca090a2a5ed60846d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27cbeeea5685fd0c81daea5b0af46a5b063ca37b47b3950113a5044226d4322c573ccb920329634189c0d4935f93dc6dde5aee710f4b937ebb4753f3ef87bd33
|
7
|
+
data.tar.gz: 3cbe2a3accfd50b08a0b10efb210ef279ffe54f03ac955c37e949e225a97c50696f54fcca15034d4b5e3b160b8ae5a78db61b796a7c132d4acb7a79d5837615d
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
data/bin/shiritori
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'shiritori'
|
4
|
+
require 'optparse'
|
4
5
|
|
5
|
-
|
6
|
+
options = { mode: 'normal' }
|
7
|
+
|
8
|
+
opt_parse = OptionParser.new do |opt|
|
9
|
+
opt.banner = 'Usage: shiritori [options]'
|
10
|
+
opt.on('-m', '--mode', 'set shiritori difficulty') { |mode| options[:mode] = mode }
|
11
|
+
end
|
12
|
+
|
13
|
+
Shiritori::CLI.start(options)
|
data/lib/shiritori.rb
CHANGED
data/lib/shiritori/cli.rb
CHANGED
data/lib/shiritori/convert.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class String
|
2
|
-
BLANK_PATTERN =
|
2
|
+
BLANK_PATTERN = /^[[:space:]]*$/
|
3
3
|
|
4
4
|
def blank?
|
5
5
|
self.size == 0 or self == BLANK_PATTERN
|
@@ -7,7 +7,7 @@ class String
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class NilClass
|
10
|
-
def
|
10
|
+
def __to_s__
|
11
11
|
'nil'
|
12
12
|
end
|
13
13
|
end
|
@@ -18,7 +18,7 @@ module Kernel
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Object
|
21
|
-
def
|
21
|
+
def __to_s__
|
22
22
|
inspect
|
23
23
|
end
|
24
24
|
end
|
@@ -30,7 +30,7 @@ BasicObject.class_eval do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
class BasicObject
|
33
|
-
def
|
33
|
+
def __to_s__
|
34
34
|
self
|
35
35
|
end
|
36
36
|
|
@@ -42,5 +42,5 @@ class BasicObject
|
|
42
42
|
::Kernel.eval(str, __binding__)
|
43
43
|
end
|
44
44
|
|
45
|
-
alias_method :to_s, :
|
45
|
+
alias_method :to_s, :__to_s__
|
46
46
|
end
|
@@ -1,19 +1,9 @@
|
|
1
1
|
module Shiritori
|
2
2
|
module SearchMethod
|
3
|
-
UNUSE_METHOD = [:exit]
|
3
|
+
UNUSE_METHOD = [:exit, :abort]
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
@method_list = scan_methods
|
8
|
-
|
9
|
-
@method_list - UNUSE_METHOD
|
10
|
-
end
|
11
|
-
|
12
|
-
def scan_methods(klass = BasicObject)
|
13
|
-
klasses = ObjectSpace.each_object(Class).to_a
|
14
|
-
klasses |= klasses.map(&:singleton_class)
|
15
|
-
|
16
|
-
klasses.map(&:instance_methods).inject(&:|)
|
5
|
+
def get_all_methods
|
6
|
+
ObjectSpace.each_object(Module).map(&:instance_methods).inject(&:|) - UNUSE_METHOD
|
17
7
|
end
|
18
8
|
end
|
19
9
|
end
|
data/lib/shiritori/shiritori.rb
CHANGED
@@ -50,7 +50,7 @@ module Shiritori
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def init(mode)
|
53
|
-
@all_method =
|
53
|
+
@all_method = get_all_methods
|
54
54
|
@current_class = Object
|
55
55
|
@current_chain = []
|
56
56
|
@used_method_list = []
|
@@ -73,7 +73,7 @@ module Shiritori
|
|
73
73
|
end
|
74
74
|
end.join
|
75
75
|
|
76
|
-
@current_chain << @current_object.
|
76
|
+
@current_chain << @current_object.__to_s__
|
77
77
|
@success = true
|
78
78
|
break
|
79
79
|
rescue Exception => ex
|
@@ -135,10 +135,10 @@ module Shiritori
|
|
135
135
|
elsif action == :exit
|
136
136
|
break
|
137
137
|
elsif @all_method.include?(action)
|
138
|
-
puts "Exec command #{[@current_object.
|
138
|
+
puts "Exec command #{[@current_object.__to_s__, command].join('.')}"
|
139
139
|
@current_chain << command
|
140
140
|
update(action: action, object: object)
|
141
|
-
elsif used_method_list
|
141
|
+
elsif used_method_list.include?(action)
|
142
142
|
$error_message = "#{action} is already used."
|
143
143
|
raise Shiritori::UseSameMethodError
|
144
144
|
end
|
@@ -172,7 +172,7 @@ module Shiritori
|
|
172
172
|
rescue Exception => ex
|
173
173
|
@error_count += 1
|
174
174
|
$error_message = ex.message
|
175
|
-
failed_message("Exec command #{[@current_object.
|
175
|
+
failed_message("Exec command #{[@current_object.__to_s__, command].join('.')}")
|
176
176
|
failed_message("Failed! : #{$error_message}")
|
177
177
|
return false
|
178
178
|
end
|
@@ -190,7 +190,7 @@ module Shiritori
|
|
190
190
|
if mode == :easy
|
191
191
|
puts "You can use methods: #{can_use_methods.sample(5).inspect}"
|
192
192
|
else
|
193
|
-
puts "\e[#{RED}mOh..
|
193
|
+
puts "\e[#{RED}mOh.. Sorry, help command can use when easy mode.\e[m"
|
194
194
|
end
|
195
195
|
|
196
196
|
new_line
|
data/lib/shiritori/version.rb
CHANGED
data/lib/shiritori/view.rb
CHANGED
@@ -38,7 +38,7 @@ module Shiritori
|
|
38
38
|
puts "+#{'-' * chain_size}+"
|
39
39
|
|
40
40
|
cls = "#{current_class}"
|
41
|
-
obj = "#{current_object.
|
41
|
+
obj = "#{current_object.__to_s__}"
|
42
42
|
cls_size = ["#{current_class}".size, 13].max + PADDING
|
43
43
|
cnt_size = 11 + PADDING
|
44
44
|
obj_size = ["#{current_object}".size, 14].max + PADDING
|
data/shiritori.gemspec
CHANGED
@@ -12,17 +12,14 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = %q{shiritori}
|
13
13
|
spec.homepage = "https://github.com/siman-man/shiritori"
|
14
14
|
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = '>= 2.0.0'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
|
-
spec.add_dependency "thor"
|
22
|
-
|
23
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
23
|
spec.add_development_dependency "rake"
|
25
24
|
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "guard"
|
27
|
-
spec.add_development_dependency "guard-rspec"
|
28
25
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'stringio'
|
3
2
|
|
4
3
|
describe "Shiritori test" do
|
@@ -22,6 +21,17 @@ describe "Shiritori test" do
|
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
24
|
+
describe 'use same method' do
|
25
|
+
it 'UseSameMethodError occur' do
|
26
|
+
fake_stdin(%w("Ruby" nil? nil?)) do
|
27
|
+
expect { shiritori.start }.to output(/Can't use same method/).to_stdout
|
28
|
+
end
|
29
|
+
|
30
|
+
expect(shiritori.current_object).to eq(false)
|
31
|
+
expect(shiritori.error_count).to eq(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
25
35
|
describe 'Timeout' do
|
26
36
|
context 'Timeout::Error occur' do
|
27
37
|
it 'first object sleep' do
|
data/spec/spec_helper.rb
CHANGED
@@ -60,7 +60,15 @@ module Helpers
|
|
60
60
|
expect(__result__).to eq __expect__
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
|
-
RSpec.configure do |
|
65
|
-
|
63
|
+
|
64
|
+
RSpec.configure do |config|
|
65
|
+
config.include(Helpers)
|
66
|
+
|
67
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
68
|
+
|
69
|
+
config.order = :random
|
70
|
+
|
71
|
+
config.expect_with :rspec do |c|
|
72
|
+
c.syntax = :expect
|
73
|
+
end
|
66
74
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shiritori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- siman-man
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: thor
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,34 +52,6 @@ dependencies:
|
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: guard-rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
55
|
description: shiritori
|
98
56
|
email:
|
99
57
|
- k128585@ie.u-ryukyu.ac.jp
|
@@ -103,9 +61,9 @@ extensions: []
|
|
103
61
|
extra_rdoc_files: []
|
104
62
|
files:
|
105
63
|
- ".gitignore"
|
64
|
+
- ".rspec"
|
106
65
|
- ".travis.yml"
|
107
66
|
- Gemfile
|
108
|
-
- Guardfile
|
109
67
|
- LICENSE.txt
|
110
68
|
- README.md
|
111
69
|
- Rakefile
|
@@ -172,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
130
|
requirements:
|
173
131
|
- - ">="
|
174
132
|
- !ruby/object:Gem::Version
|
175
|
-
version:
|
133
|
+
version: 2.0.0
|
176
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
135
|
requirements:
|
178
136
|
- - ">="
|
@@ -180,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
138
|
version: '0'
|
181
139
|
requirements: []
|
182
140
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.6.8
|
184
142
|
signing_key:
|
185
143
|
specification_version: 4
|
186
144
|
summary: shiritori
|
data/Guardfile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# A sample Guardfile
|
2
|
-
# More info at https://github.com/guard/guard#readme
|
3
|
-
|
4
|
-
guard :rspec do
|
5
|
-
watch(%r{^spec/.+_spec\.rb$})
|
6
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
-
watch('spec/spec_helper.rb') { "spec" }
|
8
|
-
|
9
|
-
# Rails example
|
10
|
-
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
-
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
-
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
-
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
-
watch('config/routes.rb') { "spec/routing" }
|
15
|
-
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
-
|
17
|
-
# Capybara features specs
|
18
|
-
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
-
|
20
|
-
# Turnip features and steps
|
21
|
-
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
-
end
|
24
|
-
|