lib/configliere/define.rb in configliere-0.0.3 vs lib/configliere/define.rb in configliere-0.0.4

- old
+ new

@@ -11,31 +11,31 @@ # Settings.define 'delorean.power_source', :description => 'Delorean subsytem supplying power to the Flux Capacitor.' # Settings.define :password, :required => true, :obscure => true # def define param, definitions={} self.param_definitions[param].merge! definitions - self.use(:environment) if definitions.include?(:encrypted) - self.use(:encrypted) if definitions.include?(:encrypted) + self.use(:env_var) if definitions.include?(:env_var) + self.use(:encrypted) if definitions.include?(:encrypted) self[param] = definitions[:default] if definitions.include?(:default) - self.environment_variables definitions[:environment], param if definitions.include?(:environment) + self.env_vars definitions[:env_var], param if definitions.include?(:env_var) end def param_definitions # initialize the param_definitions as an auto-vivifying hash if it's never been set @param_definitions ||= Sash.new{|hsh, key| hsh[key] = Sash.new } end # performs type coercion def resolve! resolve_types! - begin ; super() ; rescue NoMethodError ; nil ; end + super() self end def validate! validate_requireds! - begin ; super() ; rescue NoMethodError ; nil ; end + super() true end # =========================================================================== # @@ -161,20 +161,20 @@ # @example # Settings.define :foo # Settings.foo = 4 # Settings.foo #=> 4 def method_missing meth, *args - meth.to_s =~ /^(\w+)(=)?$/ - name, setter = [$1, $2] - super unless name && param_definitions.include?(name) + meth.to_s =~ /^(\w+)(=)?$/ or return super + name, setter = [$1.to_sym, $2] + return(super) unless param_definitions.include?(name) if setter && (args.size == 1) - self[$1] = args.first + self[name] = args.first elsif (!setter) && args.empty? - self[meth] + self[name] else super ; end end - end + end Param.class_eval do include Configliere::Define end end