nakajima-nakajima 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nakajima.rb ADDED
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'nakajima')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'nakajima', 'core_ext')
3
+
4
+ # gems
5
+ require 'rubygems'
6
+ require 'colored'
7
+ require 'metaid'
8
+
9
+ # core ruby extensions
10
+ require 'proc'
11
+ require 'object'
12
+
13
+ module Nakajima
14
+ VERSION = '0.0.1'
15
+ end
@@ -0,0 +1,36 @@
1
+ module Nakajima
2
+ module Object
3
+ module InstanceMethods
4
+ def try(method_id, *args, &block)
5
+ respond_to?(method_id) ? send(method_id, *args, &block) : nil
6
+ end
7
+
8
+ # Like JavaScript, but in Ruby...
9
+ def with(hash)
10
+ hash.each do |key, value|
11
+ meta_def(key) { hash[key] }
12
+ meta_def("#{key}=") { |v| hash[key] = v }
13
+ end
14
+
15
+ return unless block_given?
16
+
17
+ result = yield
18
+
19
+ hash.each do |key, value|
20
+ meta_eval { remove_method(key) }
21
+ meta_eval { remove_method("#{key}=") }
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ unless respond_to?(:instance_exec)
28
+ def instance_exec(*arguments, &block)
29
+ block.bind(self)[*arguments]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ Object.send :include, Nakajima::Object::InstanceMethods
@@ -0,0 +1,33 @@
1
+ # For making nicer CLI tools that take a while to do things
2
+ #
3
+ # Example:
4
+ #
5
+ # with_progress do
6
+ # sleep 2 # or some slow task
7
+ # end
8
+ #
9
+ # You can also pass in options to customize messages as well
10
+ # as the rate of the progress output.
11
+ def with_progress(options={})
12
+ options[:before] ||= "" # Message to print before starting
13
+ options[:after] ||= "" # Message to print after completion
14
+ options[:char] ||= '.' # Character to be printed as progress
15
+ options[:rate] ||= 0.2 # Delay between printing :char option
16
+ options[:change] ||= 1 # Allows for the rate to accelerate/decelerate
17
+
18
+ print options[:before]
19
+
20
+ thread = Thread.new do
21
+ printer = proc do |interval|
22
+ print(options[:char])
23
+ $stdout.flush
24
+ sleep interval
25
+ printer.call [interval * options[:change], 0.01].max
26
+ end
27
+ printer.call options[:rate]
28
+ end
29
+
30
+ yield and thread.kill
31
+
32
+ puts options[:after]
33
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nakajima-nakajima
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pat Nakajima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: colored
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: metaid
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description:
34
+ email: patnakajima@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - lib/nakajima
43
+ - lib/nakajima/core_ext
44
+ - lib/nakajima/core_ext/object.rb
45
+ - lib/nakajima/ui
46
+ - lib/nakajima/ui/progress.rb
47
+ - lib/nakajima.rb
48
+ has_rdoc: false
49
+ homepage: http://github.com/nakajima/nakajima
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.2.0
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: Stuff I use 2 or 10 projects a project.
74
+ test_files: []
75
+