bazaarvoice / cloudformation-ruby-dsl

Ruby DSL for creating Cloudformation templates
Apache License 2.0
210 stars 76 forks source link

Keyword arguments do not work in Ruby 1.9 #59

Closed oshmyrko closed 9 years ago

oshmyrko commented 9 years ago

In this commit you've added new method and variable with keyword argument:

  def initialize(**args)
    Aws.config[:region] = args[:region] if args.key?(:region)
  end

  aws_cfn = AwsCfn.new(region: template.aws_region)

but keyword arguments work only with Ruby 2.0. Does it mean that we should use cloudformation-ruby-dsl with Ruby 2.0 or it's just a mistake?

Thanks!

jonaf commented 9 years ago

Hi @oshmyrko , good find! Looks like we either need to stop supporting Ruby 1.9, require Ruby 2.0, or fix this for backward compatibility with Ruby 1.9. I guess we should fix this to support Ruby 1.9. @temujin9 Any thoughts/preference on this? I don't think there's anything else that is incompatible with Ruby 1.9 ...

temujin9 commented 9 years ago

Let's keep Ruby 1.9 compatibility, at least for as long as it's simple to do so.

jonaf commented 9 years ago

Created #61 for this issue. @temujin9 care to take a quick look for me? Thanks.

oshmyrko commented 9 years ago

Hi @jonaf, I'm not well familiar with Ruby, but I have one more question. Should this line also be changed - validate_params: false? Seems this error is caused by that line:

/var/lib/gems/1.9.1/gems/cloudformation-ruby-dsl-1.0.3/lib/cloudformation-ruby-dsl/cfntemplate.rb:52: syntax error, unexpected keyword_end, expecting $end
    from ./logstash.rb:4:in `<main>'

Thanks!

jonaf commented 9 years ago

@oshmyrko I didn't get this error in Ruby 1.9.3-p551_1. What version of Ruby are you running? This error is due to the trailing comma, which is a preferred code style and acceptable in most places in most versions of Ruby (apparently, 1.9.1 doesn't like the trailing comma in method parameters?).

oshmyrko commented 9 years ago

I'm using Ruby 1.9.3p484:

$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

$ gem which cloudformation-ruby-dsl
/var/lib/gems/1.9.1/gems/cloudformation-ruby-dsl-1.0.3/lib/cloudformation-ruby-dsl.rb
jonaf commented 9 years ago

That's odd ... Why does gem indicate you have cloudformation-ruby-dsl installed for ruby 1.9.1, but your version of Ruby is 1.9.3?

oshmyrko commented 9 years ago

Found this - Why are we installing Ruby 1.9.2/1.9.3 gems into a 1.9.1 folder?, and this.

In Ruby 1.9.0, the C interface was changed from the Ruby 1.8 series.
Gems that compile to native code had to be recompiled.
The interface was again changed in Ruby 1.9.1 and kept the same in Ruby 1.9.2 & 3. This explains the 1.9.1 you are seeing in your path.

Seems it is normal.

oshmyrko commented 9 years ago

Thank you @jonaf, it is working now.