2012-07-28 48 views
0

我想用格律與我的品牌新的Rails使用的項目像1.9哈希運行阿房宮語法

before_filter :guest_user,  only: [:new, :create] 
    before_filter :correct_user, only: :destroy 

Ruby 1.9的哈希語法做的事情,我得到這個錯誤:

/Users/xxx/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/racc/parser.rb:351:in `on_error': (Racc::ParseError) 
parse error on value ":" (tCOLON) 

我做了一些調查,發現ruby_parser gem不支持1.9哈希語法(see github issue) - 不知道哪個版本引用了我試圖將ruby_parser gem更新爲2.3.1,這不起作用,因爲有些度量中包含的代碼質量工具需要2.0版本s的ruby_parser。

有什麼辦法解決這個問題(除了回滾到舊的語法)?我也有點困惑,因爲一些代碼質量工具似乎相當過時,檢查RubyToolBox證實了這種印象。還是我錯過了一些基本的東西?

(這是我參考Gemfile.lock的):

GEM 
     remote: https://rubygems.org/ 
     specs: 
     Saikuro (1.1.0) 
     actionmailer (3.2.6) 
      actionpack (= 3.2.6) 
      mail (~> 2.4.4) 
     actionpack (3.2.6) 
      activemodel (= 3.2.6) 
      activesupport (= 3.2.6) 
      builder (~> 3.0.0) 
      erubis (~> 2.7.0) 
      journey (~> 1.0.1) 
      rack (~> 1.4.0) 
      rack-cache (~> 1.2) 
      rack-test (~> 0.6.1) 
      sprockets (~> 2.1.3) 
     activemodel (3.2.6) 
      activesupport (= 3.2.6) 
      builder (~> 3.0.0) 
     activerecord (3.2.6) 
      activemodel (= 3.2.6) 
      activesupport (= 3.2.6) 
      arel (~> 3.0.2) 
      tzinfo (~> 0.3.29) 
     activeresource (3.2.6) 
      activemodel (= 3.2.6) 
      activesupport (= 3.2.6) 
     activesupport (3.2.6) 
      i18n (~> 0.6) 
      multi_json (~> 1.0) 
     addressable (2.2.8) 
     arel (3.0.2) 
     arrayfields (4.7.4) 
     awesome_print (1.0.2) 
     bcrypt-ruby (3.0.1) 
     bootstrap-sass (2.0.4.0) 
     bootstrap-will_paginate (0.0.7) 
      will_paginate 
     builder (3.0.0) 
     capybara (1.1.2) 
      mime-types (>= 1.16) 
      nokogiri (>= 1.3.3) 
      rack (>= 1.0.0) 
      rack-test (>= 0.5.4) 
      selenium-webdriver (~> 2.0) 
      xpath (~> 0.1.4) 
     childprocess (0.3.4) 
      ffi (~> 1.0, >= 1.0.6) 
     chronic (0.3.0) 
     churn (0.0.13) 
      chronic (>= 0.2.3) 
      hirb 
      json_pure 
      main 
      ruby_parser (~> 2.0.4) 
      sexp_processor (~> 3.0.3) 
     coffee-rails (3.2.2) 
      coffee-script (>= 2.2.0) 
      railties (~> 3.2.0) 
     coffee-script (2.2.0) 
      coffee-script-source 
      execjs 
     coffee-script-source (1.3.3) 
     colored (1.2) 
     cucumber (1.2.1) 
      builder (>= 2.1.2) 
      diff-lcs (>= 1.1.3) 
      gherkin (~> 2.11.0) 
      json (>= 1.4.6) 
     cucumber-rails (1.3.0) 
      capybara (>= 1.1.2) 
      cucumber (>= 1.1.8) 
      nokogiri (>= 1.5.0) 
     database_cleaner (0.7.2) 
     diff-lcs (1.1.3) 
     erubis (2.7.0) 
     execjs (1.4.0) 
      multi_json (~> 1.0) 
     factory_girl (3.5.0) 
      activesupport (>= 3.0.0) 
     factory_girl_rails (3.5.0) 
      factory_girl (~> 3.5.0) 
      railties (>= 3.0.0) 
     faker (1.0.1) 
      i18n (~> 0.4) 
     fattr (2.2.1) 
     ffi (1.1.0) 
     flay (1.4.3) 
      ruby_parser (~> 2.0) 
      sexp_processor (~> 3.0) 
     flog (2.5.3) 
      ruby_parser (~> 2.0) 
      sexp_processor (~> 3.0) 
     gherkin (2.11.1) 
      json (>= 1.4.6) 
     growl (1.0.3) 
     guard (1.2.3) 
      listen (>= 0.4.2) 
      thor (>= 0.14.6) 
     guard-rspec (1.2.0) 
      guard (>= 1.1) 
     guard-spork (1.1.0) 
      guard (>= 1.1) 
      spork (>= 0.8.4) 
     hike (1.2.1) 
     hirb (0.7.0) 
     i18n (0.6.0) 
     journey (1.0.4) 
     jquery-rails (2.0.2) 
      railties (>= 3.2.0, < 5.0) 
      thor (~> 0.14) 
     json (1.7.3) 
     json_pure (1.7.3) 
     launchy (2.1.0) 
      addressable (~> 2.2.6) 
     libwebsocket (0.1.4) 
      addressable 
     listen (0.4.7) 
      rb-fchange (~> 0.0.5) 
      rb-fsevent (~> 0.9.1) 
      rb-inotify (~> 0.8.8) 
     mail (2.4.4) 
      i18n (>= 0.4.0) 
      mime-types (~> 1.16) 
      treetop (~> 1.4.8) 
     main (4.7.1) 
     map (6.2.0) 
     metric_fu (2.1.1) 
      Saikuro (>= 1.1.0) 
      activesupport (>= 2.0.0) 
      chronic (~> 0.3.0) 
      churn (>= 0.0.7) 
      flay (>= 1.2.1) 
      flog (>= 2.3.0) 
      rails_best_practices (>= 0.6.4) 
      rcov (>= 0.8.3.3) 
      reek (>= 1.2.6) 
      roodi (>= 2.1.0) 
      syntax 
     metrical (0.1.0) 
      metric_fu (~> 2.1.1) 
      rcov (~> 0.9) 
     mime-types (1.19) 
     multi_json (1.3.6) 
     nokogiri (1.5.5) 
     pg (0.14.0) 
     polyglot (0.3.3) 
     progressbar (0.11.0) 
     rack (1.4.1) 
     rack-cache (1.2) 
      rack (>= 0.4) 
     rack-ssl (1.3.2) 
      rack 
     rack-test (0.6.1) 
      rack (>= 1.0) 
     rails (3.2.6) 
      actionmailer (= 3.2.6) 
      actionpack (= 3.2.6) 
      activerecord (= 3.2.6) 
      activeresource (= 3.2.6) 
      activesupport (= 3.2.6) 
      bundler (~> 1.0) 
      railties (= 3.2.6) 
     rails_best_practices (1.10.1) 
      activesupport 
      awesome_print 
      colored 
      erubis 
      i18n 
      progressbar 
      sexp_processor 
     railties (3.2.6) 
      actionpack (= 3.2.6) 
      activesupport (= 3.2.6) 
      rack-ssl (~> 1.3.2) 
      rake (>= 0.8.7) 
      rdoc (~> 3.4) 
      thor (>= 0.14.6, < 2.0) 
     rake (0.9.2.2) 
     rb-fchange (0.0.5) 
      ffi 
     rb-fsevent (0.9.1) 
     rb-inotify (0.8.8) 
      ffi (>= 0.5.0) 
     rcov (0.9.11) 
     rdoc (3.12) 
      json (~> 1.4) 
     reek (1.2.12) 
      ripper_ruby_parser (~> 0.0.7) 
      ruby2ruby (~> 1.2.5) 
      ruby_parser (~> 2.0) 
      sexp_processor (~> 3.0) 
     ripper_ruby_parser (0.0.8) 
      sexp_processor (~> 3.0) 
     roodi (2.1.0) 
      ruby_parser 
     rspec (2.11.0) 
      rspec-core (~> 2.11.0) 
      rspec-expectations (~> 2.11.0) 
      rspec-mocks (~> 2.11.0) 
     rspec-core (2.11.1) 
     rspec-expectations (2.11.1) 
      diff-lcs (~> 1.1.3) 
     rspec-mocks (2.11.1) 
     rspec-rails (2.11.0) 
      actionpack (>= 3.0) 
      activesupport (>= 3.0) 
      railties (>= 3.0) 
      rspec (~> 2.11.0) 
     ruby2ruby (1.2.5) 
      ruby_parser (~> 2.0) 
      sexp_processor (~> 3.0) 
     ruby_parser (2.0.6) 
      sexp_processor (~> 3.0) 
     rubyzip (0.9.9) 
     sass (3.1.20) 
     sass-rails (3.2.5) 
      railties (~> 3.2.0) 
      sass (>= 3.1.10) 
      tilt (~> 1.3) 
     selenium-webdriver (2.25.0) 
      childprocess (>= 0.2.5) 
      libwebsocket (~> 0.1.3) 
      multi_json (~> 1.0) 
      rubyzip 
     sexp_processor (3.0.10) 
     simplecov (0.6.4) 
      multi_json (~> 1.0) 
      simplecov-html (~> 0.5.3) 
     simplecov-html (0.5.3) 
     spork (0.9.2) 
     sprockets (2.1.3) 
      hike (~> 1.2) 
      rack (~> 1.0) 
      tilt (~> 1.1, != 1.3.0) 
     sqlite3 (1.3.6) 
     syntax (1.0.0) 
     thor (0.15.4) 
     tilt (1.3.3) 
     treetop (1.4.10) 
      polyglot 
      polyglot (>= 0.3.1) 
     tzinfo (0.3.33) 
     uglifier (1.2.6) 
      execjs (>= 0.3.0) 
      multi_json (~> 1.3) 
     will_paginate (3.0.3) 
     xpath (0.1.4) 
      nokogiri (~> 1.3) 

    PLATFORMS 
     ruby 

    DEPENDENCIES 
     arrayfields 
     bcrypt-ruby 
     bootstrap-sass 
     bootstrap-will_paginate 
     capybara 
     coffee-rails 
     cucumber-rails 
     database_cleaner 
     factory_girl_rails 
     faker 
     fattr 
     growl 
     guard-rspec 
     guard-spork 
     jquery-rails 
     launchy 
     map 
     metrical 
     pg 
     rails (= 3.2.6) 
     rb-fsevent 
     rspec-rails 
     sass-rails 
     simplecov 
     spork 
     sqlite3 
     uglifier 
     will_paginate 

回答

2

在這個問題上的印象是ruby_parser不會一會兒被更新在做一些調查研究後(看https://github.com/seattlerb/ruby_parser雖然)我」我決定最後去討論這個討厭的黑客攻擊,用舊的語法來取代我的紅寶石哈希。我爲此編寫了一個rake任務,在一次運行中很容易替換它們,運行度量,然後將它們還原爲其良好的1.9哈希語法。

https://github.com/bkleinen/hash-reverter

更新:顯然,ruby_parser將與3.0.0版本更新,但大多數的工具依賴於舊版本。

+1

metric_fu 3.0現在支持完整的ruby 1.9(我是維護者)。 https://github.com/metricfu/metric_fu – BF4 2013-02-12 02:01:34