LWRP Boolean


#1

Ohai Chefs!

What’s the “correct” way to have a boolean attribute in a LWRP? There’s no Boolean class in Ruby, so

attribute :some_boolean, :kind_of => Boolean, :default => false

is not possible.

What’s the solution?

Thanks,

  • cassiano

#2

:kind_of => [TrueClass, FalseClass]
-t

On Fri, Apr 12, 2013 at 1:56 PM, Cassiano Leal cassianoleal@gmail.comwrote:

Ohai Chefs!

What’s the “correct” way to have a boolean attribute in a LWRP? There’s no
Boolean class in Ruby, so

attribute :some_boolean, :kind_of => Boolean, :default => false

is not possible.

What’s the solution?

Thanks,

  • cassiano

#3

Hi Cassiano,

A common trick to implement this, which I’ve seen across a number of LWRPs is to do:

:kind_of => [TrueClass, FalseClass]

See also: https://github.com/opscode-cookbooks/supervisor/blob/master/resources/fcgi.rb#L34


Graham Christensen

On Friday, April 12, 2013 at 8:56 AM, Cassiano Leal wrote:

Ohai Chefs!

What’s the “correct” way to have a boolean attribute in a LWRP? There’s no Boolean class in Ruby, so

attribute :some_boolean, :kind_of => Boolean, :default => false

is not possible.

What’s the solution?

Thanks,

  • cassiano

#4

:kind_of => [TrueClass, FalseClass], :default => false

did it.

Thanks, guys!

  • cassiano

On Friday, April 12, 2013 at 09:59, Graham Christensen wrote:

Hi Cassiano,

A common trick to implement this, which I’ve seen across a number of LWRPs is to do:

:kind_of => [TrueClass, FalseClass]

See also: https://github.com/opscode-cookbooks/supervisor/blob/master/resources/fcgi.rb#L34


Graham Christensen

On Friday, April 12, 2013 at 8:56 AM, Cassiano Leal wrote:

Ohai Chefs!

What’s the “correct” way to have a boolean attribute in a LWRP? There’s no Boolean class in Ruby, so

attribute :some_boolean, :kind_of => Boolean, :default => false

is not possible.

What’s the solution?

Thanks,

  • cassiano