Class: ConfigScript

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/el4r/el4r-sub.rb

Instance Method Summary collapse

Methods included from Enumerable

#build_hash, #map_with_index, #mapf

Constructor Details

#initialize(arg) ⇒ ConfigScript

Returns a new instance of ConfigScript.



902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'lib/el4r/el4r-sub.rb', line 902

def initialize(arg)
  unless Hash === arg
    eval(readf(arg.to_s))
    arg = instance_variables.map{|iv|
      [iv[1..-1], instance_variable_get(iv)]
    }.build_hash{|kv| kv}
  end
  
  s_class = class << self; self end
  arg.each do |k,v|
    if Symbol === k
      arg.delete k
      k = k.to_s
      arg[k]=v
    end

    s_class.class_eval do
      define_method(k) {arg[k].unproc}
      define_method("#{k}=") {|v| arg[k]=v}
    end
  end
  @hash = arg
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



933
934
935
# File 'lib/el4r/el4r-sub.rb', line 933

def method_missing(name, *args, &block)
  nil
end

Instance Method Details

#[]=(k, v) ⇒ Object



929
930
931
# File 'lib/el4r/el4r-sub.rb', line 929

def []=(k,v)
  @hash[k.to_s]=v
end