brice 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ # Basic initialization for IRb
2
+
3
+ brice 'init' => nil do |config|
4
+
5
+ $KCODE = 'u'
6
+
7
+ IRB.conf[:AUTO_INDENT] = true
8
+
9
+ # Cf. <http://rubyforge.org/snippet/detail.php?type=snippet&id=22>
10
+ def aorta(obj)
11
+ tempfile = Tempfile.new('aorta')
12
+ YAML.dump(obj, tempfile)
13
+ tempfile.close
14
+
15
+ path = tempfile.path
16
+
17
+ system(ENV['VISUAL'] || ENV['EDITOR'] || 'vi', path)
18
+ return obj unless File.exists?(path)
19
+
20
+ content = YAML.load_file(path)
21
+ tempfile.unlink
22
+ content
23
+ end
24
+
25
+ end
@@ -0,0 +1,32 @@
1
+ # Prompt configuration
2
+
3
+ brice 'prompt' => nil do |config|
4
+
5
+ class IRB::Context
6
+ %w[prompt_i prompt_s prompt_c prompt_n return_format].each { |name|
7
+ define_method(name) {
8
+ ivar = instance_variable_get("@#{name}")
9
+ ivar.respond_to?(:call) ? ivar['%.4f' % @runtime] : ivar
10
+ }
11
+ }
12
+
13
+ alias_method :_brice_original_evaluate, :evaluate
14
+
15
+ # Capture execution time
16
+ def evaluate(line, line_no)
17
+ @runtime = Benchmark.realtime { _brice_original_evaluate(line, line_no) }
18
+ end
19
+ end
20
+
21
+ IRB.conf[:PROMPT] ||= {} # prevent error in webrick
22
+
23
+ IRB.conf[:PROMPT][:BRICE] = { # name of prompt mode
24
+ :PROMPT_I => ' ', # normal prompt
25
+ :PROMPT_S => ' ', # prompt for continuing strings
26
+ :PROMPT_C => ' ', # prompt for continuing statement
27
+ :RETURN => lambda { |rt| "#{rt} => %s\n" } # format to return value
28
+ }
29
+
30
+ IRB.conf[:PROMPT_MODE] = :BRICE
31
+
32
+ end
@@ -0,0 +1,86 @@
1
+ # Rails settings (cf. <http://www.quotedprintable.com/2007/9/13/my-irbrc>)
2
+
3
+ brice 'rails' => nil do |config|
4
+
5
+ if rails_env = ENV['RAILS_ENV']
6
+ ### prompt
7
+ hint = rails_env == 'development' ? '' : "@#{rails_env}"
8
+
9
+ svn = brice_require('nuggets/file/which') { File.which('svn') }
10
+
11
+ if svn and svn_info = YAML.load(`#{svn} info`)
12
+ repo = svn_info['Repository Root']
13
+ path = svn_info['URL'].sub(%r{#{Regexp.escape(repo)}/?}, '')
14
+
15
+ prompt = File.basename(repo) << hint
16
+ prompt << " [#{path}]" unless path.empty?
17
+ else
18
+ prompt = File.basename(Dir.pwd) << hint
19
+ end
20
+
21
+ # add "ENV['RAILS_SANDBOX'] = 'true'" in rails-X.X.X/lib/commands/console.rb
22
+ prompt << "#{ENV['RAILS_SANDBOX'] ? '>' : '$'} "
23
+
24
+ IRB.conf[:PROMPT] ||= {}
25
+
26
+ IRB.conf[:PROMPT][:RAILS] = {
27
+ :PROMPT_I => prompt,
28
+ :PROMPT_S => prompt,
29
+ :PROMPT_C => prompt,
30
+ :RETURN => IRB.conf[:PROMPT][:BRICE][:RETURN]
31
+ }
32
+
33
+ IRB.conf[:PROMPT_MODE] = :RAILS
34
+
35
+ ### logger
36
+ brice_require 'logger' do
37
+
38
+ silence {
39
+ Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
40
+ }
41
+
42
+ define_irb_method(:logger) { |*args|
43
+ if args.empty?
44
+ RAILS_DEFAULT_LOGGER
45
+ else
46
+ level, previous_level = args.first, logger.level
47
+
48
+ logger.level = level.is_a?(Integer) ?
49
+ level : Logger.const_get(level.to_s.upcase)
50
+
51
+ if block_given?
52
+ begin
53
+ yield # RDoc: Warning: yield outside of method
54
+ ensure
55
+ logger.level = previous_level
56
+ end
57
+ else
58
+ logger
59
+ end
60
+ end
61
+ }
62
+
63
+ end
64
+
65
+ # people/6 ;-) ...inspired by:
66
+ # <http://github.com/xaviershay/dotfiles/tree/master/irbrc>
67
+ define_irb_method(:method_missing) { |method, *args|
68
+ begin
69
+ klass = method.to_s.classify.constantize
70
+
71
+ unless klass.respond_to?(:/)
72
+ if klass.respond_to?(:[])
73
+ class << klass; alias_method :/, :[]; end
74
+ else
75
+ class << klass; alias_method :/, :find; end
76
+ end
77
+ end
78
+
79
+ klass
80
+ rescue NameError
81
+ super
82
+ end
83
+ }
84
+ end
85
+
86
+ end
@@ -0,0 +1,7 @@
1
+ # Useful settings when developing Ruby libraries
2
+
3
+ brice 'devel' => nil do |config|
4
+
5
+ $:.unshift('lib') if File.directory?('lib')
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jens Wille
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-nuggets
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Extra cool IRb goodness for the masses
26
+ email: jens.wille@uni-koeln.de
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - COPYING
33
+ - ChangeLog
34
+ - README
35
+ files:
36
+ - lib/brice/init.rb
37
+ - lib/brice/version.rb
38
+ - lib/brice/dsl.rb
39
+ - lib/brice/config.rb
40
+ - lib/rc/010_libs.rb
41
+ - lib/rc/040_rails.rb
42
+ - lib/rc/015_utility_belt.rb
43
+ - lib/rc/030_prompt.rb
44
+ - lib/rc/050_devel.rb
45
+ - lib/rc/020_init.rb
46
+ - lib/rc/005_added_methods.rb
47
+ - lib/rc/004_wirble.rb
48
+ - lib/brice.rb
49
+ - COPYING
50
+ - README
51
+ - ChangeLog
52
+ - Rakefile
53
+ has_rdoc: true
54
+ homepage: http://prometheus.rubyforge.org/brice
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --line-numbers
58
+ - --inline-source
59
+ - --title
60
+ - brice Application documentation
61
+ - --charset
62
+ - UTF-8
63
+ - --main
64
+ - README
65
+ - --all
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project: prometheus
83
+ rubygems_version: 1.3.1
84
+ signing_key:
85
+ specification_version: 2
86
+ summary: Extra cool IRb goodness for the masses
87
+ test_files: []
88
+