lib/figleaf/configuration.rb in figleaf-0.0.4 vs lib/figleaf/configuration.rb in figleaf-0.0.5

- old
+ new

@@ -30,20 +30,27 @@ eval(IO.read(local_settings_path), binding) if File.exists?(local_settings_path) end end def method_missing(method_name, *args) - if self.auto_define && method_name.to_s =~ /=$/ && args.length == 1 - self.define_cattr_methods(method_name) + getter_name, modifier = extract_getter_name_and_modifier(method_name) + + if self.auto_define && modifier == '=' && args.length == 1 + self.define_cattr_methods(getter_name) self.send(method_name, args.shift) + elsif modifier == '?' && args.empty? + self.send(getter_name).present? else super end end - def define_cattr_methods(setter_name) - getter_name = setter_name.to_s.gsub('=','') + def extract_getter_name_and_modifier(method_name) + match = method_name.to_s.match(/(?<name>.*?)(?<modifier>[?=]?)$/) + [match[:name], match[:modifier]] + end + def define_cattr_methods(getter_name) cattr_writer getter_name define_singleton_method(getter_name) do result = class_variable_get "@@#{getter_name}" result.respond_to?(:call) ? result.call : result end