Module: Sketches
- Defined in:
- lib/sketches/version.rb,
lib/sketches/cache.rb,
lib/sketches/config.rb,
lib/sketches/sketch.rb,
lib/sketches/sketches.rb,
lib/sketches/temp_sketch.rb,
lib/sketches/exceptions/unknown_sketch.rb,
lib/sketches/exceptions/editor_not_defined.rb
Overview
– Sketches - A Ruby library for live programming and code reloading.
Copyright © 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ++
Defined Under Namespace
Modules: Config Classes: Cache, EditorNotDefined, Sketch, TempSketch, UnknownSketch
Constant Summary collapse
- VERSION =
Sketches version
'0.1.1'
- @@sketches_cache =
nil
Class Method Summary collapse
-
.cache ⇒ Object
The cache of sketches.
-
.config(options = {}) ⇒ Object
Configure Sketches with the given options.
-
.from(path) ⇒ Object
Creates a new sketch using the specified path.
-
.name(id, name) ⇒ Object
Names the sketch with the specified id with the specified name.
-
.print ⇒ Object
Print out all of the sketches.
-
.save(id_or_name, path) ⇒ Object
Saves the sketch with the specified id_or_name to the specified path.
-
.sketch(id_or_name) ⇒ Object
Edits the sketch with the specified id_or_name.
Class Method Details
.cache ⇒ Object
The cache of sketches.
77 78 79 80 81 82 83 |
# File 'lib/sketches/sketches.rb', line 77 def Sketches.cache unless @@sketches_cache @@sketches_cache = Cache.new end return @@sketches_cache end |
.config(options = {}) ⇒ Object
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}"
}
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sketches/sketches.rb', line 48 def Sketches.config(={}) if [:tmpdir] Config.tmpdir = [:tmpdir] end if [:background] Config.background = [:background] end if [:terminal] Config.terminal = [:terminal] end if [:editor] Config.editor = [:editor] end if [:pause] Config.pause = [:pause] end return nil end |
.from(path) ⇒ Object
Creates a new sketch using the specified path.
Sketches.from 'path/to/foo.rb'
107 108 109 110 111 112 113 |
# 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 |
.name(id, name) ⇒ Object
Names the sketch with the specified id with the specified name.
Sketches.name 2, :foo
120 121 122 123 124 |
# 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 ⇒ Object
Print out all of the sketches.
145 146 147 |
# File 'lib/sketches/sketches.rb', line 145 def Sketches.print Sketches.cache.synchronize { puts Sketches.cache } end |
.save(id_or_name, path) ⇒ Object
134 135 136 137 138 139 140 |
# 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 |