FSDB to turn file systems into applications

Discussion in 'Ruby' started by i.script@gmail.com, Mar 14, 2006.

  1. Guest

    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::Database.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
    , Mar 14, 2006
    #1
    1. Advertising

  2. > 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::Database.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?
    Matthias Georgi, Mar 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    2
    Views:
    626
  2. MattC
    Replies:
    2
    Views:
    412
    Andrea Desole
    Oct 20, 2005
  3. ytfilter

    About fsdb Dump using ncvhdl

    ytfilter, Mar 5, 2008, in forum: VHDL
    Replies:
    1
    Views:
    1,687
  4. Jonas Hartmann
    Replies:
    6
    Views:
    411
    Jonas Hartmann
    Jun 25, 2005
  5. Eric Osman
    Replies:
    2
    Views:
    351
    Eric Osman
    Apr 14, 2004
Loading...

Share This Page