• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

DBでDATETIME型で保存していたのですが、1.0で動かそうとしたらupdated_at(flash側ではDate)がInvalidDateと表示されてしまう。MYSQLクライアントでSELECTしたら特に問題なさそう。??と思ったのですが動いたのでメモ。

修正したところ

  • DB側はDATETIMEではなくてDATE
    下にあるように親和性が高いカラムのほうが楽だと判断しDATE型にしました。DATEといっても日付と時間も格納してくれます。
  • parameterで渡すのはDateのインスタンス
    getTime()だとNumberが帰ってしまうので、INSERTはOKなんだけど、SELECTしてblog.updated_atとすると”Invalid Date”といわれてしまう。

   1  stmt.parameter[":updated_at"] = new Date(); //OK
   2  stmt.parameter[":updated_at"] = new Date().getTime(); //NG:beta3までは動いてた

サポートされるSQLの仕様:local database

http://livedocs.adobe.com/air/1/jslr/localDatabaseSQLSupport.html

サポートされる型で特に親和性が高いもの

The affinity of a column is the recommended type for data stored in that column. When a value is stored in a column (through an INSERT or UPDATE statement), the runtime attempts to convert that value from its data type to the specified affinity
http://livedocs.adobe.com/air/1/jslr/localDatabaseSQLSupport.html#columnAffinit

下記のカラムとは親和性があり、実行時にデータ型を変換してくれるそうです。

  • TEXT (or STRING)
  • NUMERIC
  • INTEGER
  • REAL (or NUMBER)
  • BOOLEAN
  • DATE
  • XML
  • XMLLIST
  • OBJECT
  • NONE

DATEの親和性

A column with DATE affinity stores date and time values. A DATE column is designed to accept values that are ActionScript or JavaScript Date instances. If an attempt is made to store a String value in a DATE column, the runtime attempts to convert it to a Julian date. If the conversion fails an error occurs. If code attempts to store a Number, int, or uint value, no attempt is made to validate the data and it is assumed to be a valid Julian date value. A DATE value that's retrieved using a SELECT statement is automatically converted to a Date instance. DATE values are stored as Julian date values using the REAL storage class, so sorting and comparing operations work as you would expect them to.

NOTE:太字は私が強調をつけたところです。

posted by Png satoko on Wed 26 Mar 2008 at 10:08

via: http://blog.obiefernandez.com/content/2008/03/big-name-compan.html

フツーにいっぱいありますね。JP Morganみたいな硬いところが使っているのが新鮮。けど社内用がメインかしらん。

http://www.workingwithrails.com/high-profile-organisationsより

  • amazon.com
  • BBC
  • CapGemini
  • BPN
  • Cisco
  • C|Net
  • EA (Electronic Arts)
  • IBM
  • JP Morgan
  • NASA
  • Oakley
  • Oracle
  • Siemens
  • ♫ ThoughtWorks ♫
  • Yahoo!

Obieさんのクライアント、友達から聞いて多分使っているところ

  • John Deere
  • New York Times
  • NBC
  • Barclays
  • LA Times
  • Chicago Tribune
  • Orbitz
  • Google
  • Turner Media
  • Limewire

http://rails100.pbwiki.com/より

  • twitter.com [642 !!?! I thought it would be higher]
  • scribd.com [940]
  • blingee.com [1170]
  • yellowpages.com [1734]
  • penny-arcade.com [2069]
  • 43things.com [4190]
  • kongregate.com [4488]
  • pitchforkmedia.com [4740]
  • projectpath.com [5041 One of the Basecamp hostnames]
  • funnyordie.com [5089]
posted by Png satoko on Sat 22 Mar 2008 at 22:30

下記の日本語ページに説明がありますが、svnのコミットメッセージにIssueIDを入れることでcloseしたり関連付けたりすることができます。

http://redmine.jp/tech_note/subversion/

   1  $ svn commit -m '○○○機能を利用時の△△△な問題を修正。 refs 123'

しかし、実際には英語ページにあるように#123などのように#がないとRedmineに認識されません。
3/12 (追記) #がなくても(#をつけても、どちらでも)ちゃんと関連付け/closeされます。前田@Redmine.JPさんに指摘いただきました。ありがとうございまっす。

http://www.redmine.org/wiki/1/RedmineSettings

   1  This commit refs #1, #2 and fixes #3

ちなみにDefaultのキーワードは下記。+IssueIDは空白、カンマ、&で分割されます。

  • for referencing issues: refs, references, IssueID
  • for fixing issues: fixes, closes

After a keyword issue IDs can be separated with a space, a comma or &.

posted by Png satoko on Fri 7 Mar 2008 at 11:28 with 2 comments

プラグインを作るのに手間取ったのでメモ。
ARに機能を追加させるようなプラグインのテストを書く際、AR派生クラスをnewしてメソッドを呼び動作を確かめたりしたくなります(私の場合、privateメソッドを呼びたくなった)。でもテストのためだけにテーブルを作るのはばからしい。でMockを使う方法、ARのテスト用Mockの登場です。

ポイントとしては、MockBaseで一旦ARを派生させてから、MockBaseを派生させたクラスを作るのがミソです。そうすることで他のテストに影響を与えないようにすることができます(tips from takiuchi)。

あともう一つ、environment.rbをズズーっとロードすることでRails全体を読み込むことができます。それによってARを使えるようになります。

   1  #acts_as_notifiable_test.rb
   2  begin
   3    require File.dirname(__FILE__) + '/../../../../config/environment'
   4  rescue LoadError
   5    require 'rubygems'
   6    gem 'activerecord'
   7    require 'active_record'
   8  end
   9  
  10  class MockBase < ActiveRecord::Base; end
  11  MockBase.class_eval do
  12    alias_method :save, :valid?
  13    def self.columns() @columns ||= []; end
  14  
  15    def self.column(name, sql_type = nil, default = nil, null = true)
  16      columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
  17    end
  18  end
  19  
  20  class MockModel < MockBase
  21    acts_as_notifiable :callback => :after_create, :message => "hello", :recipients => "test@gmail.com"
  22  end
  23  
  24  class ActsAsNotifiableTest < Test::Unit::TestCase
  25    def test_option_message_string
  26      assert_equal "hello", MockModel.new.instance_eval{jabber_message}
  27    end

Reference

posted by Png satoko on Thu 6 Mar 2008 at 10:57

自分用メモ。

  • Object#instance_evalを使う
  • インスタンスに対してでないとだめ
    • NG: Object.instance_eval
    • OK: Object.new.instance_eval

Example

   1  class Post
   2    private 
   3    def title; "My blog"; end
   4  end

   1  p = Post.new
   2  p.instance_eval(title)
   3  # => "My blog"

Reference

http://doc.loveruby.net/refm/api/view/method/Object/i/instance_eval

posted by Png satoko on Thu 6 Mar 2008 at 10:24

Redmineを使っていて、Issueの追加/変更通知がGTalkで来たらうれしいかもと思って作りました:acts_as_notifiable。

NOTE:

Repository

http://svn.s21g.com/public/rails/plugins/acts_as_notifiable/

Redmineに組み込む

  1. XMPP4Rをインストール: http://xmpp4r.rubyforge.org/

       1  $sudo gem install xmpp4r
    

  2. プラグインをインストール

  3. 設定ファイルを作成: #{RAILS_ROOT}/config/acts_as_notifiable.yml
       1  #{RAILS_ROOT}/config/acts_as_notifiable.yml
       2  to:
       3    recipients: you@gmail.com me@gmail.com
       4  from:
       5    id: your_notify_account@gmail.com
       6    password: pass
       7    connect: talk.google.com
    
  4. モデルにacts_as_notifiableを追加
       1  class Issue
       2    acts_as_notifiable :message => Proc.new {|o| "[#{o.project.name}:#{o.class.name}##{o.id}]#{o.status.name}:#{o.subject}\n #{o.journals.last.notes unless o.journals.blank?}"}
    
  5. サーバ再起動

NOTE: 通知を受け取るIM側でyour_notify_account@gmail.comを追加するの忘れないように!

posted by Png satoko on Thu 6 Mar 2008 at 05:29

英語の記事を書いていて、「私にemail送って」が"send it to me"だったか、"send it for me"だったか悩んだりするときにぐぐると便利です。この場合はどちらも意味としては通ると思いますが、前者のほうが一般的のように思います。

"send * me"でぐぐる

前置詞がわからない場合。
http://www.google.com/search?name=f&hl=en&q=send+*+me
するとSend a copy to me.という文等がハイライトされて、toが良さそうだと判断できます。

"send to me", "send for me"でぐぐって検索結果数を比較する

どっちの用例が一般的かよくわからない場合。
検索結果が多いほうがよく使われると推測できるので、"send it to me"を使うほうがいいと判断します。自分の意図したいことが何なのか考えて選択して下さい。

本もあります

posted by Png satoko on Tue 4 Mar 2008 at 14:02