Module: Luruju::Configuratable

Included in:
Configuration
Defined in:
lib/luruju/enjoy_ruby.rb

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/luruju/enjoy_ruby.rb', line 108

def method_missing method, *args
  return @configrations[method].value if @configrations.key? method.to_sym
  if args.size == 1
  sym = method.to_s.match(/^(.+?)=$/).captures[0].to_sym
  return @configrations[sym].value = args[0] if @configrations.key? sym
  end
  super
end

Class Method Details

.included(base) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/luruju/enjoy_ruby.rb', line 63

def self.included base
  base.parent.class_eval "  @@config = nil\n  def self.config() @@config || \#{base.name}.default end\n  def self.config=(config) @@config = config end\n  EOD\n  base.class_eval <<-EOD\n  @@default_configurations = {}\n  def self.default() new end   \n  def self.uninstall() parent.config = nil end\n  def self.install(config=default, &block)\n    return parent.config = config unless block_given?\n    parent.config = new {|config|yield config}\n    end\n  def self.define_config key, options={}\n    @@default_configurations[key] = Config.new(key, options[:default], options[:validate])\n  end\n  def initialize\n    @configrations = {}\n    @@default_configurations.each{|key, value| @configrations[key] = value.dup}\n    yield self if block_given?\n  end\n  def self.singleton_method_added name\n    return unless name.to_s.match(/default_(.+)$/)\n    key = $1.to_sym\n    return unless @@default_configurations[key]\n    @@default_configurations[key].default = method(name).call\n  end\n  EOD\nend\n"