Class: Jello::Mould
- Inherits:
-
Object
- Object
- Jello::Mould
- Defined in:
- lib/jello/mould.rb
Instance Attribute Summary collapse
-
#on_paste(&block) ⇒ Object
Acts as both a getter and a setter for the @on_paste attribute.
Class Method Summary collapse
-
.find(name) ⇒ Object
This checks the Jello require paths for a mould by that name.
Instance Method Summary collapse
-
#initialize(pasteboard = nil, &block) ⇒ Mould
constructor
Creates a new Mould.
-
#method_missing(meth, *args) ⇒ Object
We pass any missing methods on to the Pasteboard.
Constructor Details
#initialize(pasteboard = nil, &block) ⇒ Mould
Creates a new Mould. Takes a block to be run on every paste.
61 62 63 64 65 66 |
# File 'lib/jello/mould.rb', line 61 def initialize pasteboard = nil, &block @pasteboard = pasteboard || Pasteboard::General @on_paste = block Moulds[@pasteboard] << self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
We pass any missing methods on to the Pasteboard.
72 73 74 |
# File 'lib/jello/mould.rb', line 72 def method_missing meth, *args @pasteboard.send meth, *args end |
Instance Attribute Details
#on_paste(&block) ⇒ Object
Acts as both a getter and a setter for the @on_paste attribute. If passed a block, it sets that block as the @on_paste hook - else it returns the current hook block.
43 44 45 |
# File 'lib/jello/mould.rb', line 43 def on_paste @on_paste end |
Class Method Details
.find(name) ⇒ Object
This checks the Jello require paths for a mould by that name. The following directories are checked, in this order:
- `$HOME/.jello/*.rb`
- `/etc/jello/*.rb`
- `$JELLO_SRC/moulds/*.rb`
The first one with a file by the correct name will overide any later ones.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jello/mould.rb', line 19 def self.find name [File.join(ENV['HOME'], '.jello'), File.join('etc', 'jello'), File.join( File.dirname(__FILE__), '..', '..', 'moulds' )].each do |dir| dir = File.(dir) if File.directory? dir Dir["#{dir}/**/*.rb"].each do |file| # This should be quite powerful - if you have a directory of # moulds, you can select them all, or you can select all of them # plus a single-file mould of the same name. Or whatever you might # want. Mmmsexy? Mmmsexy. return file if file.gsub(/^#{dir}/, '') =~ /#{name}/ end end end return nil end |