Module Sketches
In: lib/sketches/version.rb
lib/sketches/sketch.rb
lib/sketches/config.rb
lib/sketches/temp_sketch.rb
lib/sketches/cache.rb
lib/sketches/exceptions/unknown_sketch.rb
lib/sketches/exceptions/editor_not_defined.rb
lib/sketches/sketches.rb
StandardError UnknownSketch RuntimeError EditorNotDefined Tempfile TempSketch Hash Cache Sketch Config Sketches dot/f_1.png

Methods

cache   config   from   name   print   save   sketch  

Classes and Modules

Module Sketches::Config
Class Sketches::Cache
Class Sketches::EditorNotDefined
Class Sketches::Sketch
Class Sketches::TempSketch
Class Sketches::UnknownSketch

Constants

VERSION = '0.1.1'   Sketches version

Public Class methods

The cache of sketches.

[Source]

# File lib/sketches/sketches.rb, line 77
  def Sketches.cache
    unless @@sketches_cache
      @@sketches_cache = Cache.new
    end

    return @@sketches_cache
  end

Configure Sketches with the given options.

options may contain the following keys:

:tmpdir:Directory to store temporary sketches in. Defaults to Dir.tmpdir if unspecified.
:background:Specifies wether to run the editor as a background or a foreground process.
:terminal:The terminal to optionally run the editor within.
:editor:The editor to use to edit sketches.
:pause:The number of seconds to pause in-between checking if any sketches were modified.
  Sketches.config :editor => 'gvim', :pause => 2

  Sketches.config :editor => 'vim',
                  :background => true,
                  :terminal => lambda { |cmd|
                    "xterm -fg gray -bg black -e #{cmd.dump}"
                  }

[Source]

# File lib/sketches/sketches.rb, line 48
  def Sketches.config(options={})
    if options[:tmpdir]
      Config.tmpdir = options[:tmpdir]
    end

    if options[:background]
      Config.background = options[:background]
    end

    if options[:terminal]
      Config.terminal = options[:terminal]
    end

    if options[:editor]
      Config.editor = options[:editor]
    end

    if options[:pause]
      Config.pause = options[:pause]
    end

    return nil
  end

Creates a new sketch using the specified path.

  Sketches.from 'path/to/foo.rb'

[Source]

# File lib/sketches/sketches.rb, line 107
  def Sketches.from(path)
    Sketches.cache.synchronize do
      sketch = Sketches.cache.reuse_sketch(path)

      sketch.synchronize { sketch.edit }
    end
  end

Names the sketch with the specified id with the specified name.

  Sketches.name 2, :foo

[Source]

# File lib/sketches/sketches.rb, line 120
  def Sketches.name(id,name)
    Sketches.cache.synchronize do
      Sketches.cache.name_sketch(id,name)
    end
  end

Print out all of the sketches.

[Source]

# File lib/sketches/sketches.rb, line 145
  def Sketches.print
    Sketches.cache.synchronize { puts Sketches.cache }
  end

Saves the sketch with the specified id_or_name to the specified path.

  Sketches.save 2, 'path/to/example.rb'

  Sketches.save :foo, 'path/to/foo.rb'

[Source]

# File lib/sketches/sketches.rb, line 134
  def Sketches.save(id_or_name,path)
    Sketches.cache.synchronize do
      if (sketch = Sketches.cache[id_or_name])
        sketch.save(path)
      end
    end
  end

Edits the sketch with the specified id_or_name. If no sketch exists with the specified id_or_name, one will be created.

  Sketches.sketch 2

  Sketches.sketch :foo

[Source]

# File lib/sketches/sketches.rb, line 93
  def Sketches.sketch(id_or_name)
    Sketches.cache.synchronize do
      sketch = Sketches.cache[id_or_name]
      sketch ||= Sketches.cache.new_sketch(id_or_name)

      sketch.synchronize { sketch.edit }
    end
  end

[Validate]