Sha256: b92b23cb488c348135f6aff03832b2592340d203bf2072580d032c160b95876c

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'yaml'

irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
cmd_opts = {:irb => irb}

module Ritalin
  PATH_TO_FILE = `echo $HOME`.strip + "/.ritalinrc"
  
  class Profile
    attr_accessor :libs, :name

    def initialize name,libs=[]
      self.name,self.libs = name,libs
    end
    
    def add_to_file
      File.open(PATH_TO_FILE,'a') {|f| f.puts self.to_yaml.gsub("---","\n") }
    end
    
    def self.list
      YAML::load File.read(PATH_TO_FILE)
    end
    
    def self.output_list
      self.list.each do |p,libs|
        puts "name: #{p}"
        puts "libs: #{libs.join(", ")}"
        puts "-------------------------"
      end
    end
    
    def self.find name
      raise "Invaid Profile" unless list.keys.include?(name.to_sym)
      new name,list[name.to_sym]
    end
    
    def irb_cmd
      "irb -r #{self.libs.join(" -r")}"
    end
    
    def to_yaml
      {name.to_sym => self.libs}.to_yaml
    end
    
  end
  
  class CmdParser
    
    def initialize args
      action_for_cmd args
    end
    
    def action_for_cmd args
      case
        when args.include?("-a")
          profile_name, *libs = args - ["-a"]
          Profile.new(profile_name,libs).add_to_file
        when args.include?("-l")
          Profile.output_list
        else
          system Profile.find(args.first).irb_cmd
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ritalin-0.0.1 lib/ritalin.rb