reading Rails 3 Release Note (8:Active Model to 7:Action Pack)
Rails に対して「ここはちょっとなー」と思っていた、表面はエレガントだが内部のコードはダーティという水鳥な部分が払拭されたように見える。
フルアーマーZZみたいだ!と思っていた重厚長大感もモジュール&粗結合で回答が出たような。
spec 見てるだけの今の段階ではかなりの好印象
開発効率を上げる&バグを減らすアプローチとして、抽象化はとても大事だと思う訳ですよ。
複数の手続きに名前を付けてカプセル化し、テストを付けて再利用する、、普段のアプリケーション開発なんてその繰り返しなんじゃないかと。
Rails にはそのための機能が揃っていて嬉しい。
- AM の validation はとても良いように思える。
- AR 含め、Rails2 系の API が使えるのは 3.2 まで
- will not deplicated until 3.1 and not removed until Rails 3.2
- compatibility layer でサポートって面白い。
- AR で State Machine サポート
- REST 厨だけど業務に於いて State Machine 欲しい場面は多々有る。デフォで State Machine が入ってくるのはデカい。
note の写経になるとあまり意味が無い事に気付いた。
mind-map 代わりにと思ったが、note が既に mind-map 状態なのでサブセットを作るだけだったり。
次は補足だけ記そう、、、、
source
Active Model
- all ORM plugin need to implement Active Model interface
# custom validator class TitleValidator < ActiveModel::EachValidator Titles = ['Mr.', 'Mrs.', "Dr."] def validate_each(record, attr, value) record.errors[attr] << 'must be a valid title' unless Titles.include?(value) end end # validate with plain object class Person include ActiveModel::Validations attr_accessor :title validates :title, :presence => true, :title => true end # validate with AR class Person < ActiveRecord::Base validates :title, :presence => true, :title => true end
Active Record
- see the doc: http://guides.rails.info/3_0_release_notes.html#active-record
- http://m.onkey.org/2010/1/22/active-record-query-interface
- http://hasmanyquestions.wordpress.com/2010/01/17/let-your-sql-growl-in-rails-3/
Enhancements
- :destroyed?
- :inverse_of allowing you to pull instance of an already loaded association without hitting db
Patches and Deprications
- pgsql support for the XML data type col
- a lot
- named_scope is now just "scope"
- scope :since, lambda {|time| where("created_at > ?", time)}
- save(false) is now save(:validate => false)
- i18n err msg is now :en.errors.template
- model.errors.on is now model.errors[]
- validate_presence_of is now :presence => true
- colored logging is now Rails::Subscriber.colorize_logging or config.colorize_logging
Active Resource
extracted to Active Model
see doc http://guides.rails.info/3_0_release_notes.html#active-resource
Active Support
- Safe Buffers are implemented in ActiveSupport::SafeBuffer
- what's that ? like a object-escaper or cache of escaped input values or so ?
- added Array.uniq_by, uniq_by!
- added ActiveSupport::Notifications middleware
- what's that ?
- escape_html_entities_in_json now defaults to false
- string.mb_chars
- added SAX-based parser for XmlMini, using LibXML and Nokogiri
- added Object.presence returns object if it's #present? otherwise returns nil
- use .exclude? instead of if ! x.include?
- support deep-merging in HashWithIndifferentAccess
object tap (ruby 1.9)
- helper for call chaining
- passes its object into the given block, and gets block's return
"hoge".tap do |o| o.capitalize end # gets Hoge ? # I haven't run it yet.