diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-03 15:03:18 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-23 15:23:01 -0700 |
commit | 2278a61bc0fafe7fdd208c30b12cc11db9547d04 (patch) | |
tree | c3553d800581e515a238cf5b7a161fcae7ff5c33 /lib/chef/resource.rb | |
parent | 4e34d816167af65b36c7a57ad33dca3b1f39c1e4 (diff) | |
download | chef-2278a61bc0fafe7fdd208c30b12cc11db9547d04.tar.gz |
Add property Type as an alias to is
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r-- | lib/chef/resource.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 712b7b36cb..39435d557d 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -719,6 +719,8 @@ class Chef # defined by this resource, this will *override* the previous value. # # @param name [Symbol] The name of the property. + # @param type [Object,Array<Object>] The type(s) of this property. + # If present, this is prepended to the `is` validation option. # @param options [Hash<Symbol,Object>] Validation options. # @option options [Object,Array] :is An object, or list of # objects, that must match the value using Ruby's `===` operator @@ -759,15 +761,26 @@ class Chef # be run in the context of the instance (and able to access other # properties). # - # @return [Chef::Resource::PropertyType] The property type. - # - # @example With nothing + # @example Bare property # property :x # - # @example With options + # @example With just a type + # property :x, String + # + # @example With just options # property :x, default: 'hi' # - def self.property(name, **options) + # @example With type and options + # property :x, String, default: 'hi' + # + def self.property(name, type=NULL_ARG, **options) + if type != NULL_ARG + if options[:is] + options[:is] = ([ type ] + [ options[:is] ]).flatten(1) + else + options[:is] = type + end + end define_method(name) do |arg=nil| set_or_return(name.to_sym, arg, options) end |