Parent

Methods

Included Modules

Class Index [+]

Quicksearch

Gem::Commands::SingCommand

gem command to “sing” the implementation of a gem.

Constants

VERSION

Public Class Methods

new() click to toggle source
    # File lib/rubygems/commands/sing_command.rb, line 23
23:   def initialize
24:     super("sing", "\"Sing\" a gem's implementation",
25:           :version => Gem::Requirement.default)
26: 
27:     add_version_option
28:     add_local_remote_options
29:   end

Public Instance Methods

execute() click to toggle source
     # File lib/rubygems/commands/sing_command.rb, line 43
 43:   def execute
 44:     name = get_one_gem_name
 45: 
 46:     base = files = nil
 47: 
 48:     if remote? then
 49:       version = options[:version] || Gem::Requirement.default
 50:       all = Gem::Requirement.default
 51:       dep = Gem::Dependency.new name, version
 52: 
 53:       specs_and_sources = Gem::SpecFetcher.fetcher.fetch dep
 54: 
 55:       spec, source_uri = specs_and_sources.sort_by { |spec,| spec.version }.last
 56: 
 57:       alert_error "Could not find #{name} in any repository" unless spec
 58: 
 59:       gem_path = File.join "/tmp", spec.file_name
 60: 
 61:       unless File.file? gem_path then
 62:         path = Gem::RemoteFetcher.fetcher.download spec, source_uri
 63:         FileUtils.mv path, gem_path
 64:       end
 65: 
 66:       dir_path = File.join "/tmp", File.basename(gem_path, '.gem')
 67: 
 68:       unless File.directory? dir_path then
 69:         FileUtils.mkdir_p dir_path
 70:         Gem::Installer.new(gem_path, :unpack => true).unpack dir_path
 71:       end
 72: 
 73:       Dir.chdir dir_path do
 74:         files = spec.require_paths.map { |d| Dir["#{d}/**/*.rb"] }.flatten.sort
 75:       end
 76: 
 77:       base = dir_path
 78:     else
 79:       dep = Gem::Dependency.new name, options[:version]
 80:       specs = Gem.source_index.search dep
 81: 
 82:       if specs.empty? then
 83:         alert_error "No installed gem #{dep}"
 84:         terminate_interaction 1
 85:       end
 86: 
 87:       spec  = specs.last
 88:       base  = spec.full_gem_path
 89:       files = spec.lib_files
 90:     end
 91: 
 92:     $stdout.sync = true
 93: 
 94:     ##
 95:     # Special thanks to Ben Bleything for midiator and help getting
 96:     # this up and running!
 97: 
 98:     midi = MIDIator::Interface.new
 99:     midi.use :dls_synth
100: 
101:     # blues scale
102:     scale = [ C4, Eb4, F4, Fs4, G4, Bb4,
103:               C5, Eb5, F5, Fs5, G5, Bb5,
104:               C6, Eb6, F6, Fs6, G6, Bb6 ]
105: 
106:     midi.control_change 32, 10, 1 # TR-808 is Program 26 in LSB bank 1
107:     midi.program_change 10, 26
108: 
109:     # TODO: eventually add ability to play actual AST
110: 
111:     files.each do |path|
112:       full_path = File.join base, path
113: 
114:       next unless File.file? full_path # rails is run by MORONS
115: 
116:       warn path
117: 
118:       line_number_of_last_end = 0
119:       File.foreach full_path do |line|
120:         if line =~ /^(\s+)end$/ then
121:           distance = $INPUT_LINE_NUMBER - line_number_of_last_end
122:           note_character = "♩"
123:           duration = case distance
124:                      when 0 .. 3
125:                        note_character = "♪"
126:                        0.125
127:                      when 4 .. 10
128:                        note_character = "♩"
129:                        0.25
130:                      when 11 .. 30
131:                        note_character = "d"
132:                        0.5
133:                      else
134:                        note_character = "o"
135:                        1.0
136:                      end
137:           line_number_of_last_end = $INPUT_LINE_NUMBER
138:           num_spaces = $1.size
139: 
140:           print "#{note_character} "
141:           print line
142:           midi.play scale[ num_spaces / 2 ], duration
143:           print "\n" * (duration * 4).to_i if Gem.configuration.really_verbose
144:         end
145:       end
146: 
147:       [ HighTom1, HighTom2, LowTom1, LowTom2 ].each do |note|
148:         midi.play note, 0.067, 10
149:       end
150: 
151:       midi.play CrashCymbal1, 0.25, 10
152:     end
153: 
154:     midi.play CrashCymbal2, 0.25, 10
155:     sleep 1.0
156:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.