Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > FSDB to turn file systems into applications

Reply
Thread Tools

FSDB to turn file systems into applications

 
 
i.script@gmail.com
Guest
Posts: n/a
 
      03-14-2006
In search for a simple database system that's also an an universal
application service ( similar to Frontier) I've started again to play
around with FSDB. By accident I've found out that this way every file
system can be turned into an application. Using the incredible powerful
"method_missing" construct the following code was implemented:

require 'fsdb'

@@root = FSDB:atabase.new('/tmp/examples')
@@path = ''

script = <<MY_SCRIPT
def show_it(a,b)
puts a.to_s + b.to_s
end
MY_SCRIPT

script2 = <<MY_SCRIPT
def make_it(a,b)
puts a + ' : ' + b
end
MY_SCRIPT

script3 = <<MY_SCRIPT
def hello_method
write_it("Hello World!")
end
def write_it(txt)
puts txt
end
MY_SCRIPT

@@root['/scripts/myscripts/show_it'] = script
@@root['/scripts/make_it'] = script2
@@root['/scripts/hello_method'] = script3
@@root['/values/a'] = 25
@@root['/values/b'] = 35
@@root['/values/array'] = [31,2,3,4]


class <<
def method_missing(method_name,*args )
@@path << '/' + method_name.to_s
if !(File.directory?(@@root.absolute("#{@@path}")))
res = @@root["/#{@@path}"]
if res.to_s.include? "def"
if !(methods.include? method_name)
eval res
@@path = ''
return send(method_name,*args)
end
end
@@path = ''
return res
end
end
end


scripts.myscripts.show_it("one","two")
scripts.make_it("one","two")
scripts.hello_method()

puts values.a + values.b

myVal = values.array + [5,6,7,8]
puts myVal.to_s

So my question is: has someone else used "method_missing" this way and
are there any "show stoppers" to use "method missing" this way. I'm
planning to use this idea for a very important project and I want to
try to avoid to run into troubles because of a lack of experience.

- Tom

 
Reply With Quote
 
 
 
 
Matthias Georgi
Guest
Posts: n/a
 
      03-14-2006
> So my question is: has someone else used "method_missing" this way and
> are there any "show stoppers" to use "method missing" this way. I'm
> planning to use this idea for a very important project and I want to
> try to avoid to run into troubles because of a lack of experience.


Generally method_missing magic may lead to infinite recursion loops,
which are quite annoying. I would suggest to allow this kind of magic
only in special blocks, which are evaled in the instance scope of a
database object.

class Database
def initialize(root)
@root = FSDB:atabase.new(root)
end
def method_missing
...
end
def with(&block)
instance_eval(&block)
end
end

db = Database.new("/tmp/examples")

db.with do
scripts.myscripts.show_it("one","two")
scripts.make_it("one","two")
scripts.hello_method()
end

Note, that you lose the instance scope, so methods and instance
variables are not available in the block.

How about recognizing accessor calls for writing to the database?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
James Gosling the Creator of EMACS and JAVA - leaves ORACLE - Butthen reports started coming in of odd failures. Systems would crashstrangely. We'd get crashes in applications. All applications. Crashes in thekernel. small Pox C Programming 2 07-22-2010 10:07 PM
Maybe C is the perfect language for really good systems programmers, but unfortunately not-so-good systems and applications programmers are using it and they shouldn’t be. Casey Hawthorne C Programming 18 11-06-2009 05:05 AM
About fsdb Dump using ncvhdl ytfilter VHDL 1 03-06-2008 05:35 AM
Voip PBX,Private Phone Systems,PBX Telephone Systems, Business Phone Systems broadbandera@gmail.com UK VOIP 9 07-24-2006 03:44 PM
FSDB, Apache, FastCGI - ERROR: FSDB::Database::DirIsImmutableError Jonas Hartmann Ruby 6 06-25-2005 04:58 AM



Advertisments