my_scripts 0.0.19 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,6 +16,7 @@ tmtags
16
16
  ## PROJECT::GENERAL
17
17
  coverage
18
18
  rdoc
19
+ doc
19
20
  pkg
20
21
 
21
22
  ## PROJECT::SPECIFIC
data/Rakefile CHANGED
@@ -1,57 +1,24 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'pathname'
2
+ NAME = 'my_scripts'
3
+ BASE_DIR = Pathname.new(__FILE__).dirname
4
+ LIB_DIR = BASE_DIR + 'lib'
5
+ PKG_DIR = BASE_DIR + 'pkg'
6
+ DOC_DIR = BASE_DIR + 'rdoc'
3
7
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "my_scripts"
8
- gem.summary = "Simple framework for writing command-line scripts"
9
- gem.description = "Simple framework for writing command-line scripts and collection of my own scripts (mostly dev-related)"
10
- gem.email = "arvitallian@gmail.com"
11
- gem.homepage = "http://github.com/arvicco/my_scripts"
12
- gem.authors = ["arvicco"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_development_dependency "cucumber", ">= 0"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
21
-
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
26
- end
8
+ $LOAD_PATH.unshift LIB_DIR.to_s
9
+ require NAME
27
10
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
32
- end
33
-
34
- task :spec => :check_dependencies
11
+ CLASS_NAME = MyScripts
12
+ VERSION = CLASS_NAME::VERSION
35
13
 
36
14
  begin
37
- require 'cucumber/rake/task'
38
- Cucumber::Rake::Task.new(:features)
39
-
40
- task :features => :check_dependencies
15
+ require 'rake'
41
16
  rescue LoadError
42
- task :features do
43
- abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
44
- end
17
+ require 'rubygems'
18
+ gem 'rake', '~> 0.8.3.1'
19
+ require 'rake'
45
20
  end
46
21
 
47
- task :default => :spec
22
+ # Load rakefile tasks
23
+ Dir['tasks/*.rake'].sort.each { |file| load file }
48
24
 
49
- require 'rake/rdoctask'
50
- Rake::RDocTask.new do |rdoc|
51
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
-
53
- rdoc.rdoc_dir = 'rdoc'
54
- rdoc.title = "my_scripts #{version}"
55
- rdoc.rdoc_files.include('README*')
56
- rdoc.rdoc_files.include('lib/**/*.rb')
57
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.19
1
+ 0.0.22
@@ -22,7 +22,7 @@ module MyScripts
22
22
  system %Q[rake version:bump:patch]
23
23
  when 10..99
24
24
  system %Q[rake version:bump:minor]
25
- when 10..99
25
+ when 100
26
26
  system %Q[rake version:bump:major]
27
27
  end
28
28
  system %Q[git add --all]
@@ -8,6 +8,14 @@ module MyScripts
8
8
  @cli = cli
9
9
  end
10
10
 
11
+ def version
12
+ if self.class.const_defined? :VERSION
13
+ self.class::VERSION # Script's own version
14
+ else
15
+ VERSION # Gem version
16
+ end
17
+ end
18
+
11
19
  def run
12
20
  end
13
21
 
@@ -21,8 +29,8 @@ module MyScripts
21
29
  end
22
30
 
23
31
  def usage examples, explanation = nil
24
- puts "Usage:"
25
- puts (examples.respond_to?(:split) ? examples.split("\n") : examples).map {|line| " #{@name} #{line}"}
32
+ puts "Script #{@name} #{version} - Usage:"
33
+ (examples.respond_to?(:split) ? examples.split("\n") : examples).map {|line| puts " #{@name} #{line}"}
26
34
  puts explanation if explanation
27
35
  exit 1
28
36
  end
@@ -11,22 +11,23 @@ module MyScripts
11
11
 
12
12
  require 'win/gui/input'
13
13
 
14
- self.class.define_method :move_mouse_randomly do
15
- x, y = Win::Gui::Input::get_cursor_pos
16
- x1, y1 = x + rand(3) - 1, y + rand(3) - 1
17
- Win::Gui::Input::mouse_event(Win::Gui::Input::MOUSEEVENTF_ABSOLUTE, x1, y1, 0, 0)
18
- puts "Cursor positon set to #{x1}, #{y1}"
19
- end
20
-
14
+ self.class.send(:include, Win::Gui::Input)
21
15
  super
22
16
  end
23
17
 
18
+ def move_mouse_randomly
19
+ x, y = get_cursor_pos
20
+ x1, y1 = x + rand(3) - 1, y + rand(3) - 1
21
+ mouse_event(MOUSEEVENTF_ABSOLUTE, x1, y1, 0, 0)
22
+ puts "Cursor positon set to #{x1}, #{y1}"
23
+ end
24
+
24
25
  def run
25
26
  case @argv.size
26
27
  when 0
27
28
  sleep_time = SLEEP_TIME
28
29
  when 1
29
- sleep_time = @argv.first * 60
30
+ p sleep_time = @argv.first.to_f * 60
30
31
  else
31
32
  usage "[minutes] - prevents screen auto lock-up by moving mouse pointer every (4) [minutes]"
32
33
  end
data/lib/my_scripts.rb CHANGED
@@ -1,12 +1,24 @@
1
1
  # Top level namespace
2
2
  module MyScripts
3
+ require 'pathname'
3
4
 
4
- # Used to auto-require all the source files located in lib/my_scripts
5
- def self.require_libs( filename, filemask )
6
- file = ::File.expand_path(::File.join(::File.dirname(filename), filemask.gsub(/(?<!.rb)$/,'.rb')))
7
- require file if File.exist?(file) && !File.directory?(file)
8
- Dir.glob(file).sort.each {|rb| require rb}
5
+ VERSION_FILE = Pathname.new(__FILE__).dirname + '../VERSION' # :nodoc:
6
+ VERSION = VERSION_FILE.exist? ? VERSION_FILE.read.strip : nil
7
+
8
+ # Requires ruby source file(s). Accepts either single filename/glob or Array of filenames/globs.
9
+ # Accepts following options:
10
+ # :*file*:: Lib(s) required relative to this file - defaults to __FILE__
11
+ # :*dir*:: Required lib(s) located under this dir name - defaults to gem name
12
+ #
13
+ def self.require_libs( libs, opts={} )
14
+ file = Pathname.new(opts[:file] || __FILE__)
15
+ [libs].flatten.each do |lib|
16
+ name = file.dirname + (opts[:dir] || file.basename('.*')) + lib.gsub(/(?<!.rb)$/, '.rb')
17
+ Pathname.glob(name.to_s).sort.each {|rb| require rb}
18
+ end
9
19
  end
10
20
  end # module MyScripts
11
21
 
12
- %W[my_scripts/script my_scripts/cli **/*].each {|rb| MyScripts.require_libs(__FILE__, rb)}
22
+ # Require all ruby source files located under directory lib/my_scripts
23
+ # If you need files in specific order, you should specify it here before the glob
24
+ MyScripts.require_libs %W[script cli **/*]
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
3
+ require 'spec_helper'
4
4
 
5
5
  module MyScriptsTest
6
6
  module A
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
1
+ require 'spec_helper'
2
2
 
3
3
  module MyScriptsTest
4
4
 
@@ -31,26 +31,48 @@ module MyScriptsTest
31
31
  end
32
32
 
33
33
  describe 'Script Execution' do
34
+ MyScripts.module_eval do
35
+ # Stub script that outputs @argv, prompts to stdout and echoes/returns what it gets from stdin
36
+ class Scriptest < Script #one word for script name
37
+ def run
38
+ puts @argv
39
+ puts 'Say it:'
40
+ puts gotten = gets
41
+ gotten
42
+ end
43
+ end
44
+
45
+ # Stub script that just puts 'OK' to stdout
46
+ class SnakeScript < Script
47
+ def run
48
+ puts 'OK'
49
+ end
50
+ end
51
+
52
+ # Stub script that outputs usage notes
53
+ class UsageScript < Script
54
+ def run
55
+ usage 'Blah'
56
+ end
57
+ end
58
+
59
+ # Stub script that outputs usage notes
60
+ class VersionedUsageScript < Script
61
+ VERSION = '0.0.13'
62
+ def run
63
+ usage 'Blah'
64
+ end
65
+ end
66
+ end
34
67
 
35
68
  context 'trying to execute undefined script' do
36
69
  it 'fails' do
37
70
  cli = create_cli
38
- proc{cli.run( :undefined, [])}.should raise_error "Script MyScripts::Undefined not found"
71
+ expect{cli.run( :undefined, [])}.to raise_error "Script MyScripts::Undefined not found"
39
72
  end
40
73
  end
41
74
 
42
75
  context 'scripts without arguments' do
43
- MyScripts.module_eval do
44
- # Stub script that prompts to stdout and echoes/returns what it gets from stdin
45
- class Scriptest < Script
46
- def run
47
- puts 'Say it:'
48
- puts gotten = gets
49
- gotten
50
- end
51
- end
52
- end
53
-
54
76
  it 'cli.run executes pre-defined script' do
55
77
  cli = create_cli
56
78
  expect{cli.run :scriptest, []}.to_not raise_error
@@ -76,17 +98,6 @@ module MyScriptsTest
76
98
 
77
99
  context 'scripts with arguments' do
78
100
  before(:each) {@given_args = [1, 2, 3, :four, 'five']}
79
- MyScripts.module_eval do
80
- # Stub script that prompts to stdout and echoes/returns what it gets from stdin
81
- class Scriptest < Script
82
- def run
83
- puts @argv
84
- puts 'Say it:'
85
- puts gotten = gets
86
- gotten
87
- end
88
- end
89
- end
90
101
 
91
102
  it 'cli.run executes pre-defined script' do
92
103
  cli = create_cli
@@ -117,16 +128,27 @@ module MyScriptsTest
117
128
  end
118
129
  end
119
130
 
120
- context 'scripts with snake_case names' do
121
- MyScripts.module_eval do
122
- # Stub script that just puts 'OK' to stdout
123
- class SnakeScript < Script
124
- def run
125
- puts 'OK'
126
- end
131
+ context 'prints usage' do
132
+ context 'unversioned script' do
133
+ it 'outputs script name, GEM version and usage note to stdout, then exits' do
134
+ cli = create_cli
135
+ usage_regexp = Regexp.new("Script usage_script #{MyScripts::VERSION} - Usage")
136
+ stdout_should_receive(usage_regexp)
137
+ stdout_should_receive(/Blah/)
138
+ expect{cli.run :usage_script, []}.to raise_error SystemExit
139
+ end
140
+ end
141
+ context 'versioned script' do
142
+ it 'outputs script name, SCRIPT version and usage note to stdout, then exits' do
143
+ cli = create_cli
144
+ stdout_should_receive(/Script versioned_usage_script 0.0.13 - Usage/)
145
+ stdout_should_receive(/Blah/)
146
+ expect{cli.run :versioned_usage_script, []}.to raise_error SystemExit
127
147
  end
128
148
  end
149
+ end
129
150
 
151
+ context 'scripts with snake_case names' do
130
152
  it 'executes scripts with snake_case name' do
131
153
  cli = create_cli
132
154
  stdout_should_receive('OK')
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,6 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib my_scripts]))
1
+ require 'my_scripts'
4
2
  require 'spec'
5
3
  require 'spec/autorun'
6
4
 
7
5
  Spec::Runner.configure do |config|
8
-
9
6
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 19
9
- version: 0.0.19
8
+ - 22
9
+ version: 0.0.22
10
10
  platform: ruby
11
11
  authors:
12
12
  - arvicco
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-08 00:00:00 +04:00
17
+ date: 2010-04-12 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: "0"
44
44
  type: :development
45
45
  version_requirements: *id002
46
- description: Simple framework for writing command-line scripts and collection of my own scripts (mostly dev-related)
46
+ description: Describe package my_scripts
47
47
  email: arvitallian@gmail.com
48
48
  executables:
49
49
  - citi
@@ -60,12 +60,6 @@ extra_rdoc_files:
60
60
  - LICENSE
61
61
  - README.rdoc
62
62
  files:
63
- - .document
64
- - .gitignore
65
- - LICENSE
66
- - README.rdoc
67
- - Rakefile
68
- - VERSION
69
63
  - bin/citi
70
64
  - bin/dummy
71
65
  - bin/gitto
@@ -74,10 +68,6 @@ files:
74
68
  - bin/newscript
75
69
  - bin/rabbit
76
70
  - bin/wake
77
- - features/my_scripts.feature
78
- - features/step_definitions/my_scripts_steps.rb
79
- - features/support/env.rb
80
- - lib/my_scripts.rb
81
71
  - lib/my_scripts/citi.rb
82
72
  - lib/my_scripts/cli.rb
83
73
  - lib/my_scripts/dummy.rb
@@ -88,11 +78,19 @@ files:
88
78
  - lib/my_scripts/rabbit.rb
89
79
  - lib/my_scripts/script.rb
90
80
  - lib/my_scripts/wake.rb
91
- - my_scripts.gemspec
81
+ - lib/my_scripts.rb
92
82
  - spec/my_scripts/extensions_spec.rb
93
83
  - spec/my_scripts_spec.rb
94
84
  - spec/spec.opts
95
85
  - spec/spec_helper.rb
86
+ - features/my_scripts.feature
87
+ - features/step_definitions/my_scripts_steps.rb
88
+ - features/support/env.rb
89
+ - Rakefile
90
+ - LICENSE
91
+ - VERSION
92
+ - .gitignore
93
+ - README.rdoc
96
94
  has_rdoc: true
97
95
  homepage: http://github.com/arvicco/my_scripts
98
96
  licenses: []
@@ -122,8 +120,9 @@ rubyforge_project:
122
120
  rubygems_version: 1.3.6
123
121
  signing_key:
124
122
  specification_version: 3
125
- summary: Simple framework for writing command-line scripts
123
+ summary: Describe package my_scripts
126
124
  test_files:
127
125
  - spec/my_scripts/extensions_spec.rb
128
126
  - spec/my_scripts_spec.rb
127
+ - spec/spec.opts
129
128
  - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/my_scripts.gemspec DELETED
@@ -1,82 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{my_scripts}
8
- s.version = "0.0.19"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["arvicco"]
12
- s.date = %q{2010-04-08}
13
- s.description = %q{Simple framework for writing command-line scripts and collection of my own scripts (mostly dev-related)}
14
- s.email = %q{arvitallian@gmail.com}
15
- s.executables = ["citi", "dummy", "gitto", "jew", "mybones", "newscript", "rabbit", "wake"]
16
- s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".gitignore",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "bin/citi",
28
- "bin/dummy",
29
- "bin/gitto",
30
- "bin/jew",
31
- "bin/mybones",
32
- "bin/newscript",
33
- "bin/rabbit",
34
- "bin/wake",
35
- "features/my_scripts.feature",
36
- "features/step_definitions/my_scripts_steps.rb",
37
- "features/support/env.rb",
38
- "lib/my_scripts.rb",
39
- "lib/my_scripts/citi.rb",
40
- "lib/my_scripts/cli.rb",
41
- "lib/my_scripts/dummy.rb",
42
- "lib/my_scripts/extensions.rb",
43
- "lib/my_scripts/gitto.rb",
44
- "lib/my_scripts/jew.rb",
45
- "lib/my_scripts/mybones.rb",
46
- "lib/my_scripts/rabbit.rb",
47
- "lib/my_scripts/script.rb",
48
- "lib/my_scripts/wake.rb",
49
- "my_scripts.gemspec",
50
- "spec/my_scripts/extensions_spec.rb",
51
- "spec/my_scripts_spec.rb",
52
- "spec/spec.opts",
53
- "spec/spec_helper.rb"
54
- ]
55
- s.homepage = %q{http://github.com/arvicco/my_scripts}
56
- s.rdoc_options = ["--charset=UTF-8"]
57
- s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.6}
59
- s.summary = %q{Simple framework for writing command-line scripts}
60
- s.test_files = [
61
- "spec/my_scripts/extensions_spec.rb",
62
- "spec/my_scripts_spec.rb",
63
- "spec/spec_helper.rb"
64
- ]
65
-
66
- if s.respond_to? :specification_version then
67
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
- s.specification_version = 3
69
-
70
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
71
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
72
- s.add_development_dependency(%q<cucumber>, [">= 0"])
73
- else
74
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
75
- s.add_dependency(%q<cucumber>, [">= 0"])
76
- end
77
- else
78
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
79
- s.add_dependency(%q<cucumber>, [">= 0"])
80
- end
81
- end
82
-