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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ca46091473a69da8cca24df97a965bfd65f6300
4
- data.tar.gz: a50c380b8b86bfb402d2641da8d7477eda101b8e
3
+ metadata.gz: 04d232b530daf6a056a86f3ae98b296b8b3bc58c
4
+ data.tar.gz: b5814ea22d52b5b8325c54ca090a2a5ed60846d6
5
5
  SHA512:
6
- metadata.gz: 90aae5e28b8c64edb6097fb5434f79716776f8cd86038876824028e10cc732f163cc5ee04dda157ff6a91e308a8dcf396b84f14a0a946e9b3e01f43b964e4cf1
7
- data.tar.gz: 29c19a4710ee8a3ee4ac88aab3e86dc8ae4d464aa9b158f9a0a2b1660fac61aa5b71e4ec04dd3b759bba9d633955cfb58a76a62ddeddb3533355a0511eabd4f3
6
+ metadata.gz: 27cbeeea5685fd0c81daea5b0af46a5b063ca37b47b3950113a5044226d4322c573ccb920329634189c0d4935f93dc6dde5aee710f4b937ebb4753f3ef87bd33
7
+ data.tar.gz: 3cbe2a3accfd50b08a0b10efb210ef279ffe54f03ac955c37e949e225a97c50696f54fcca15034d4b5e3b160b8ae5a78db61b796a7c132d4acb7a79d5837615d
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
3
  .bundle
4
+ /vendor/bundle
4
5
  .config
5
6
  .yardoc
6
7
  Gemfile.lock
@@ -20,6 +21,7 @@ tmp
20
21
  # Ignore junk file
21
22
  shiritori-*/*
22
23
  doc/
24
+ .rspec_status
23
25
  **/*.swp
24
26
  *.swp
25
27
  **/*~
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml CHANGED
@@ -3,5 +3,7 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1
5
5
  - 2.2
6
+ - 2.3
7
+ - 2.4.0
6
8
 
7
9
  script: bundle exec rspec spec
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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
- Shiritori::CLI.start(ARGV)
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
@@ -1,5 +1,3 @@
1
- require "thor"
2
-
3
1
  require "shiritori/version"
4
2
  require "shiritori/search_method"
5
3
  require "shiritori/error"
data/lib/shiritori/cli.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  module Shiritori
2
- class CLI < Thor
2
+ class CLI
3
3
  GAME_MODE = [:easy, :normal]
4
4
 
5
- desc "start", "Start GAME!"
6
- option :mode
7
- def start
5
+ def self.start(options)
8
6
  mode = (options[:mode])? options[:mode].to_sym : :normal
9
7
 
10
8
  if GAME_MODE.include?(mode)
@@ -1,5 +1,5 @@
1
1
  class String
2
- BLANK_PATTERN = /^\s*$/
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 to_ss
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 to_ss
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 to_ss
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, :to_ss
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 get_all_method
6
- @check_list = {}
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
@@ -50,7 +50,7 @@ module Shiritori
50
50
  end
51
51
 
52
52
  def init(mode)
53
- @all_method = get_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.to_ss
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.to_ss, command].join('.')}"
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[action]
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.to_ss, command].join('.')}")
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.. Sory, help command is only exist easy mode.\e[m"
193
+ puts "\e[#{RED}mOh.. Sorry, help command can use when easy mode.\e[m"
194
194
  end
195
195
 
196
196
  new_line
@@ -1,3 +1,3 @@
1
1
  module Shiritori
2
- VERSION = '0.1.8'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -38,7 +38,7 @@ module Shiritori
38
38
  puts "+#{'-' * chain_size}+"
39
39
 
40
40
  cls = "#{current_class}"
41
- obj = "#{current_object.to_ss}"
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,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
  let(:__class__){ Random }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
  let(:__class__){ Range }
@@ -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
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
  let(:__class__){ Symbol }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Shiritori test" do
4
2
  let(:main){ Shiritori::Main.new }
5
3
 
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 |conf|
65
- conf.include(Helpers)
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.1.8
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: 2016-02-06 00:00:00.000000000 Z
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: '0'
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.5.1
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
-