Module: TMP::DSLCore

Included in:
DSL, InstanceDSL
Defined in:
lib/tmp/dsl.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tmp/dsl.rb', line 13

def method_missing( method, *args, &block )

  if method.to_s.reverse[0] == '='
    target_obj.__send__ :write, method.to_s.reverse.sub('=','').reverse, args.first
    return args.first
  else

    unless block.nil?

      if File.exist? File.join( target_obj.folder_path, method.to_s )
        args[0] ||= "r+"
      else
        args[0] ||= "w+"
      end

      File.open( File.join( target_obj.folder_path, method.to_s ), args[0] ,&block)

    else

      if method =~ /^\w+__path__$/
        return target_obj.__send__ :path, method.to_s.sub!( /__path__$/,"" )
      else
        return target_obj.__send__ :read, method
      end


    end

  end

end

Instance Method Details

#target_obj(obj = nil) ⇒ Object



6
7
8
9
10
11
# File 'lib/tmp/dsl.rb', line 6

def target_obj obj=nil

  @target_obj= obj unless obj.nil?
  @target_obj || ::TMP

end