akm-selectable_attr_rails 0.3.5 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /*.gem
2
+ /coverage
3
+ /pkg
4
+ /rdoc
5
+ /selectable_attr_test.sqlite3.db
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Takeshi AKIMA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,198 @@
1
+ = SelectableAttrRails
2
+
3
+ == Introduction
4
+ selectable_attr_railsは、selectable_attrをRailsで使うときに便利なヘルパーメソッドを提供し、
5
+ エントリをDBから取得したり、I18n対応するものです。
6
+ http://github.com/akm/selectable_attr_rails/tree/master
7
+
8
+ selectable_attr は、コードが割り振られるような特定の属性について*コード*、*プログラム上での名前*、
9
+ *表示するための名前*などをまとめて管理するものです。
10
+ http://github.com/akm/selectable_attr/tree/master
11
+
12
+
13
+ == Install
14
+ === 1. Railsプロジェクトで使う場合
15
+ ==== a. plugin install
16
+ ruby script/plugin install git://github.com/akm/selectable_attr.git
17
+ ruby script/plugin install git://github.com/akm/selectable_attr_rails.git
18
+
19
+ ==== b. gem install
20
+ [sudo] gem install akimatter-selectable_attr akimatter-selectable_attr_rails -s http://gems.github .com
21
+
22
+ == チュートリアル
23
+
24
+ === selectヘルパーメソッド
25
+ 以下のようなモデルが定義してあった場合
26
+ class Person < ActiveRecord::Base
27
+ include ::SelectableAttr::Base
28
+
29
+ selectable_attr :gender do
30
+ entry '1', :male, '男性'
31
+ entry '2', :female, '女性'
32
+ entry '9', :other, 'その他'
33
+ end
34
+ end
35
+
36
+ ビューでは以下のように選択肢を表示することができます。
37
+ <% form_for(:person) do |f| %>
38
+ <%= f.select :gender %>
39
+ <% end %>
40
+
41
+ form_for、fields_forを使用しない場合でも、オブジェクト名を設定して使用可能です。
42
+ <%= select :person, :gender %>
43
+
44
+ また以下のように複数の値を取りうる場合にもこのメソドを使用することが可能です。
45
+ class RoomSearch
46
+ include ::SelectableAttr::Base
47
+
48
+ multi_selectable_attr :room_type do
49
+ entry '01', :single, 'シングル'
50
+ entry '02', :twin, 'ツイン'
51
+ entry '03', :double, 'ダブル'
52
+ entry '04', :triple, 'トリプル'
53
+ end
54
+ end
55
+
56
+ <% form_for(:room_search) do |f| %>
57
+ <%= f.select :room_type %>
58
+ <% end %>
59
+
60
+ この場合、出力されるselectタグのmultiple属性が設定されます。
61
+
62
+
63
+
64
+ === radio_button_groupヘルパーメソッド
65
+ 一つだけ値を選択するUIの場合、selectメソッドではなく<input type="radio".../>を出力することも可能です。
66
+ 上記Personモデルの場合
67
+
68
+ <% form_for(:person) do |f| %>
69
+ <%= f.radio_button_group :gender %>
70
+ <% end %>
71
+
72
+ この場合、<input type="radio" .../><label for="xxx">... という風に続けて出力されるので、改行などを出力したい場合は
73
+ 引数を一つ取るブロックを渡して以下のように記述します。
74
+
75
+ <% form_for(:person) do |f| %>
76
+ <% f.radio_button_group :gender do |b| %>
77
+ <% b.each do %>
78
+ <%= b.radio_button %>
79
+ <%= b.label %>
80
+ <br/>
81
+ <% end %>
82
+ <% end %>
83
+ <% end %>
84
+
85
+ f.radio_button_groupを呼び出しているERBのタグが、<%= %>から<% %>に変わっていることにご注意ください。
86
+
87
+
88
+ === check_box_groupヘルパーメソッド
89
+ 複数の値を選択するUIの場合、selectメソッドではなく<input type="checkbox".../>を出力することも可能です。
90
+ 上記RoomSearchクラスの場合
91
+
92
+ <% form_for(:room_search) do |f| %>
93
+ <%= f.check_box_group :room_type %>
94
+ <% end %>
95
+
96
+ この場合、<input type="checkbox" .../><label for="xxx">... という風に続けて出力されるので、改行などを出力したい場合は
97
+ 引数を一つ取るブロックを渡して以下のように記述します。
98
+
99
+ <% form_for(:person) do |f| %>
100
+ <% f.check_box_group :gender do |b| %>
101
+ <% b.each do %>
102
+ <%= b.check_box %>
103
+ <%= b.label %>
104
+ <br/>
105
+ <% end %>
106
+ <% end %>
107
+ <% end %>
108
+
109
+ f.check_box_groupを呼び出しているERBのタグが、<%= %>から<% %>に変わっていることにご注意ください。
110
+
111
+
112
+ == DBからのエントリの更新/追加
113
+ 各エントリの名称を実行時に変更したり、項目を追加することが可能です。
114
+
115
+ class RoomPlan < ActiveRecord::Base
116
+ include ::SelectableAttr::Base
117
+
118
+ selectable_attr :room_type do
119
+ update_by "select room_type, name from room_types"
120
+ entry '01', :single, 'シングル'
121
+ entry '02', :twin, 'ツイン'
122
+ entry '03', :double, 'ダブル'
123
+ entry '04', :triple, 'トリプル'
124
+ end
125
+ end
126
+
127
+ というモデルと
128
+
129
+ create_table "room_types" do |t|
130
+ t.string "room_type", :limit => 2
131
+ t.string "name", :limit => 20
132
+ end
133
+
134
+ というマイグレーションで作成されるテーブルがあったとします。
135
+
136
+ === エントリの追加
137
+ room_typeが"05"、nameが"4ベッド"というレコードがINSERTされた後、
138
+ RoomPlan#room_type_optionsなどのselectable_attrが提供するメソッドで
139
+ 各エントリへアクセスすると、update_byで指定されたSELECT文が実行され、
140
+ エントリとしては、
141
+ entry '05', :entry_05, '4ベッド'
142
+ が定義されている状態と同じようになります。
143
+
144
+ このようにコードで定義されていないエントリは、DELETEされると、エントリもなくなります。
145
+
146
+ === エントリの名称の更新
147
+ 実行時に名称を変えたい場合には、そのidに該当するレコードを追加/更新します。
148
+ 例えば、
149
+ room_typeが"04"、nameが"3ベッド"というレコードがINSERTされると、その後は
150
+ 04のエントリはの名称は"3ベッド"に変わり、また別の名称にUPDATEすると、それに
151
+ よってエントリの名称も変わります。
152
+
153
+ このようにコードによってエントリが定義されている場合は、DELETEされてもエントリは削除されず、
154
+ DELETE後は、名称が元に戻ります。
155
+
156
+
157
+ == I18n対応
158
+ エントリのロケールにおける名称をRails2.2からの機能である、I18nを内部的にしようして取得できます。
159
+
160
+ 上記RoomPlanモデルの場合、
161
+
162
+ config/locales/ja.yml
163
+ ja:
164
+ selectable_attrs:
165
+ room_types:
166
+ single: シングル
167
+ twin: ツイン
168
+ double: ダブル
169
+ triple: トリプル
170
+
171
+ config/locales/en.yml
172
+ en:
173
+ selectable_attrs:
174
+ room_types:
175
+ single: Single
176
+ twin: Twin
177
+ double: Double
178
+ triple: Triple
179
+
180
+ というYAMLを用意した上で、モデルを以下のように記述します。
181
+
182
+ class RoomPlan < ActiveRecord::Base
183
+ include ::SelectableAttr::Base
184
+
185
+ selectable_attr :room_type do
186
+ i18n_scope(:selectable_attrs, :room_types)
187
+ entry '01', :single, 'シングル'
188
+ entry '02', :twin, 'ツイン'
189
+ entry '03', :double, 'ダブル'
190
+ entry '04', :triple, 'トリプル'
191
+ end
192
+ end
193
+
194
+ これで、I18n.localeに設定されているロケールに従って各エントリの名称が変わります。
195
+
196
+
197
+ == Credit
198
+ Copyright (c) 2008 Takeshi AKIMA, released under the MIT lice nse
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ gem 'rspec', '>= 1.1.4'
3
+ require 'rake'
4
+ require 'rake/rdoctask'
5
+ require 'spec/rake/spectask'
6
+ require 'spec/rake/verify_rcov'
7
+
8
+ desc 'Default: run unit tests.'
9
+ task :default => :spec
10
+
11
+ task :pre_commit => [:spec, 'coverage:verify']
12
+
13
+ desc 'Run all specs under spec/**/*_spec.rb'
14
+ Spec::Rake::SpecTask.new(:spec => 'coverage:clean') do |t|
15
+ t.spec_files = FileList['spec/**/*_spec.rb']
16
+ t.spec_opts = ["-c", "--diff"]
17
+ t.rcov = true
18
+ t.rcov_opts = ["--include-file", "lib\/*\.rb", "--exclude", "spec\/"]
19
+ end
20
+
21
+ desc 'Generate documentation for the selectable_attr_rails plugin.'
22
+ Rake::RDocTask.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'SelectableAttrRails'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ namespace :coverage do
31
+ desc "Delete aggregate coverage data."
32
+ task(:clean) { rm_f "coverage" }
33
+
34
+ desc "verify coverage threshold via RCov"
35
+ RCov::VerifyTask.new(:verify => :spec) do |t|
36
+ t.threshold = 100.0 # Make sure you have rcov 0.7 or higher!
37
+ t.index_html = 'coverage/index.html'
38
+ end
39
+ end
40
+
41
+ begin
42
+ require 'jeweler'
43
+ Jeweler::Tasks.new do |s|
44
+ s.name = "selectable_attr_rails"
45
+ s.summary = "selectable_attr_rails makes possible to use selectable_attr in rails application"
46
+ s.description = "selectable_attr_rails makes possible to use selectable_attr in rails application"
47
+ s.email = "akima@gmail.com"
48
+ s.homepage = "http://github.com/akm/selectable_attr_rails/"
49
+ s.authors = ["Takeshi Akima"]
50
+ s.add_dependency("activesupport", ">= 2.0.2")
51
+ s.add_dependency("activerecord", ">= 2.0.2")
52
+ s.add_dependency("actionpack", ">= 2.0.2")
53
+ s.add_dependency("akm-selectable_attr", ">= 0.3.5")
54
+ end
55
+ rescue LoadError
56
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
57
+ end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 3
3
- :patch: 5
3
+ :patch: 7
4
4
  :major: 0
data/init.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'selectable_attr'
2
+ require 'selectable_attr_i18n'
3
+ require 'selectable_attr_rails'
4
+
5
+ module SelectableAttr
6
+ class Enum
7
+ include ::SelectableAttrRails::DbLoadable
8
+ end
9
+ end
10
+
11
+ class ActiveRecord::Base
12
+ include ::SelectableAttr::Base
13
+ end
14
+
15
+ class ActionView::Base
16
+ include ::SelectableAttrRails::Helpers::SelectHelper::Base
17
+ include ::SelectableAttrRails::Helpers::CheckBoxGroupHelper::Base
18
+ include ::SelectableAttrRails::Helpers::RadioButtonGroupHelper::Base
19
+ end
20
+
21
+ class ActionView::Helpers::FormBuilder
22
+ include ::SelectableAttrRails::Helpers::SelectHelper::FormBuilder
23
+ include ::SelectableAttrRails::Helpers::CheckBoxGroupHelper::FormBuilder
24
+ include ::SelectableAttrRails::Helpers::RadioButtonGroupHelper::FormBuilder
25
+ end
26
+
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,74 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{selectable_attr_rails}
5
+ s.version = "0.3.7"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Takeshi Akima"]
9
+ s.date = %q{2009-08-17}
10
+ s.description = %q{selectable_attr_rails makes possible to use selectable_attr in rails application}
11
+ s.email = %q{akima@gmail.com}
12
+ s.extra_rdoc_files = [
13
+ "README"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "MIT-LICENSE",
18
+ "README",
19
+ "Rakefile",
20
+ "VERSION.yml",
21
+ "init.rb",
22
+ "install.rb",
23
+ "lib/selectable_attr_i18n.rb",
24
+ "lib/selectable_attr_rails.rb",
25
+ "lib/selectable_attr_rails/db_loadable.rb",
26
+ "lib/selectable_attr_rails/helpers.rb",
27
+ "lib/selectable_attr_rails/helpers/abstract_selection_helper.rb",
28
+ "lib/selectable_attr_rails/helpers/check_box_group_helper.rb",
29
+ "lib/selectable_attr_rails/helpers/radio_button_group_helper.rb",
30
+ "lib/selectable_attr_rails/helpers/select_helper.rb",
31
+ "lib/selectable_attr_rails/version.rb",
32
+ "selectable_attr_rails.gemspec",
33
+ "spec/database.yml",
34
+ "spec/fixtures/.gitignore",
35
+ "spec/introduction_spec.rb",
36
+ "spec/schema.rb",
37
+ "spec/selectable_attr_i18n_spec.rb",
38
+ "spec/spec_helper.rb",
39
+ "uninstall.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/akm/selectable_attr_rails/}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.4}
45
+ s.summary = %q{selectable_attr_rails makes possible to use selectable_attr in rails application}
46
+ s.test_files = [
47
+ "spec/introduction_spec.rb",
48
+ "spec/schema.rb",
49
+ "spec/selectable_attr_i18n_spec.rb",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
59
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.0.2"])
60
+ s.add_runtime_dependency(%q<actionpack>, [">= 2.0.2"])
61
+ s.add_runtime_dependency(%q<akm-selectable_attr>, [">= 0.3.5"])
62
+ else
63
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
64
+ s.add_dependency(%q<activerecord>, [">= 2.0.2"])
65
+ s.add_dependency(%q<actionpack>, [">= 2.0.2"])
66
+ s.add_dependency(%q<akm-selectable_attr>, [">= 0.3.5"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
70
+ s.add_dependency(%q<activerecord>, [">= 2.0.2"])
71
+ s.add_dependency(%q<actionpack>, [">= 2.0.2"])
72
+ s.add_dependency(%q<akm-selectable_attr>, [">= 0.3.5"])
73
+ end
74
+ end
File without changes
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akm-selectable_attr_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi Akima
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-23 00:00:00 -08:00
12
+ date: 2009-08-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -58,33 +58,38 @@ executables: []
58
58
 
59
59
  extensions: []
60
60
 
61
- extra_rdoc_files: []
62
-
61
+ extra_rdoc_files:
62
+ - README
63
63
  files:
64
+ - .gitignore
65
+ - MIT-LICENSE
66
+ - README
67
+ - Rakefile
64
68
  - VERSION.yml
69
+ - init.rb
70
+ - install.rb
65
71
  - lib/selectable_attr_i18n.rb
66
- - lib/selectable_attr_rails
72
+ - lib/selectable_attr_rails.rb
67
73
  - lib/selectable_attr_rails/db_loadable.rb
68
- - lib/selectable_attr_rails/helpers
74
+ - lib/selectable_attr_rails/helpers.rb
69
75
  - lib/selectable_attr_rails/helpers/abstract_selection_helper.rb
70
76
  - lib/selectable_attr_rails/helpers/check_box_group_helper.rb
71
77
  - lib/selectable_attr_rails/helpers/radio_button_group_helper.rb
72
78
  - lib/selectable_attr_rails/helpers/select_helper.rb
73
- - lib/selectable_attr_rails/helpers.rb
74
79
  - lib/selectable_attr_rails/version.rb
75
- - lib/selectable_attr_rails.rb
80
+ - selectable_attr_rails.gemspec
76
81
  - spec/database.yml
77
- - spec/debug.log
78
- - spec/fixtures
82
+ - spec/fixtures/.gitignore
79
83
  - spec/introduction_spec.rb
80
84
  - spec/schema.rb
81
85
  - spec/selectable_attr_i18n_spec.rb
82
86
  - spec/spec_helper.rb
83
- has_rdoc: true
87
+ - uninstall.rb
88
+ has_rdoc: false
84
89
  homepage: http://github.com/akm/selectable_attr_rails/
90
+ licenses:
85
91
  post_install_message:
86
92
  rdoc_options:
87
- - --inline-source
88
93
  - --charset=UTF-8
89
94
  require_paths:
90
95
  - lib
@@ -103,9 +108,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
108
  requirements: []
104
109
 
105
110
  rubyforge_project:
106
- rubygems_version: 1.2.0
111
+ rubygems_version: 1.3.5
107
112
  signing_key:
108
- specification_version: 2
113
+ specification_version: 3
109
114
  summary: selectable_attr_rails makes possible to use selectable_attr in rails application
110
- test_files: []
111
-
115
+ test_files:
116
+ - spec/introduction_spec.rb
117
+ - spec/schema.rb
118
+ - spec/selectable_attr_i18n_spec.rb
119
+ - spec/spec_helper.rb