selectable_attr_rails 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -11,13 +11,19 @@ http://github.com/akm/selectable_attr/tree/master
11
11
 
12
12
 
13
13
  == Install
14
- === 1. Railsプロジェクトで使う場合
15
- ==== a. plugin install
14
+ === a. plugin install
16
15
  ruby script/plugin install git://github.com/akm/selectable_attr.git
17
16
  ruby script/plugin install git://github.com/akm/selectable_attr_rails.git
18
17
 
19
- ==== b. gem install
20
- [sudo] gem install akimatter-selectable_attr akimatter-selectable_attr_rails -s http://gems.github .com
18
+ === b. gem install
19
+ [sudo] gem install selectable_attr_rails
20
+
21
+ config/initializers/selectable_attr.rb
22
+ require 'selectable_attr'
23
+ require 'selectable_attr_i18n'
24
+ require 'selectable_attr_rails'
25
+ SelectableAttrRails.setup
26
+
21
27
 
22
28
  == チュートリアル
23
29
 
data/Rakefile CHANGED
@@ -50,7 +50,7 @@ begin
50
50
  s.add_dependency("activesupport", ">= 2.0.2")
51
51
  s.add_dependency("activerecord", ">= 2.0.2")
52
52
  s.add_dependency("actionpack", ">= 2.0.2")
53
- s.add_dependency("selectable_attr", ">= 0.3.5")
53
+ s.add_dependency("selectable_attr", ">= 0.3.11")
54
54
  end
55
55
  rescue LoadError
56
56
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 10
2
+ :patch: 11
3
3
  :build:
4
4
  :major: 0
5
5
  :minor: 3
data/init.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'selectable_attr'
2
2
  require 'selectable_attr_i18n'
3
3
  require 'selectable_attr_rails'
4
-
5
- SelectableAttrRails.add_features_to_rails
4
+ SelectableAttrRails.setup
@@ -1,11 +1,14 @@
1
1
  if defined?(I18n)
2
+ require 'selectable_attr'
3
+
2
4
  module SelectableAttr
3
5
  class Enum
4
- def self.i18n_export
6
+ def self.i18n_export(enums = nil)
7
+ enums ||= instances
5
8
  result = {}
6
- instances.each do |instance|
9
+ enums.each do |instance|
7
10
  unless instance.i18n_scope
8
- # puts "no i18n_scope of #{instance.inspect}"
11
+ SelectableAttrRails.logger.debug("no i18n_scope of #{instance.inspect}")
9
12
  next
10
13
  end
11
14
  paths = instance.i18n_scope.dup
@@ -7,9 +7,14 @@ module SelectableAttrRails
7
7
  autoload :Validatable, 'selectable_attr_rails/validatable'
8
8
 
9
9
  class << self
10
+ def logger
11
+ @logger ||= Logger.new(STDERR)
12
+ end
13
+ def logger=(value)
14
+ @logger = value
15
+ end
10
16
 
11
17
  def add_features_to_active_record
12
- puts "SelectableAttrRails.add_features_to_active_record"
13
18
  ActiveRecord::Base.module_eval do
14
19
  include ::SelectableAttr::Base
15
20
  include ::SelectableAttrRails::Validatable::Base
@@ -18,6 +23,7 @@ module SelectableAttrRails
18
23
  include ::SelectableAttrRails::DbLoadable
19
24
  include ::SelectableAttrRails::Validatable::Enum
20
25
  end
26
+ logger.debug("#{self.name}.add_features_to_active_record")
21
27
  end
22
28
 
23
29
  def add_features_to_action_view
@@ -31,13 +37,20 @@ module SelectableAttrRails
31
37
  include ::SelectableAttrRails::Helpers::CheckBoxGroupHelper::FormBuilder
32
38
  include ::SelectableAttrRails::Helpers::RadioButtonGroupHelper::FormBuilder
33
39
  end
40
+ logger.debug("#{self.name}.add_features_to_action_view")
34
41
  end
35
42
 
36
43
  def add_features_to_rails
37
- puts "SelectableAttrRails.add_features_to_rails"
38
44
  add_features_to_active_record
39
45
  add_features_to_action_view
40
46
  end
47
+
48
+ def setup
49
+ logger = defined?(Rails) ? Rails.logger : ActiveRecord::Base.logger
50
+ self.logger = logger
51
+ SelectableAttr.logger = logger if SelectableAttr.respond_to?(:logger=) # since 0.3.11
52
+ add_features_to_rails
53
+ end
41
54
  end
42
55
 
43
56
  end
data/spec/database.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  sqlite:
2
2
  :adapter: sqlite
3
- :dbfile: selectable_attr_test.sqlite.db
3
+ :database: selectable_attr_test.sqlite.db
4
4
  sqlite3:
5
5
  :adapter: sqlite3
6
- :dbfile: selectable_attr_test.sqlite3.db
6
+ :database: selectable_attr_test.sqlite3.db
@@ -253,6 +253,9 @@ if defined?(I18n)
253
253
  end
254
254
 
255
255
  it 'test_i18n_export' do
256
+ io = StringIO.new
257
+ SelectableAttrRails.logger = Logger.new(io)
258
+
256
259
  I18nItemMaster.delete_all("category_name = 'product_type_cd'")
257
260
 
258
261
  I18n.locale = 'ja'
@@ -282,11 +285,26 @@ if defined?(I18n)
282
285
  {'entry1'=>"entry one",
283
286
  'entry2'=>"entry two",
284
287
  'entry3'=>"entry three"}
285
- actual['selectable_attrs'].keys.include?('ProductWithI18nDB1').should == true
288
+ actual['selectable_attrs'].keys.should include('ProductWithI18nDB1')
286
289
  actual['selectable_attrs']['ProductWithI18nDB1'].should ==
287
290
  {'product_type_cd'=>
288
291
  {'book'=>"Book", 'dvd'=>"DVD", 'cd'=>"CD", 'other'=>"Others", 'entry_04'=>"Toy"}}
289
292
  end
293
+
294
+ Enum2 = SelectableAttr::Enum.new do
295
+ entry 1, :entry1, "縁鳥1"
296
+ entry 2, :entry2, "縁鳥2"
297
+ entry 3, :entry3, "縁鳥3"
298
+ end
299
+
300
+ it "i18n_scope missing" do
301
+ io = StringIO.new
302
+ SelectableAttrRails.logger = Logger.new(io)
303
+ actual = SelectableAttr::Enum.i18n_export([Enum2])
304
+ actual.inspect.should_not =~ /縁鳥/
305
+ io.rewind
306
+ io.readline.should =~ /^no\ i18n_scope\ of\ /
307
+ end
290
308
  end
291
309
  else
292
310
  $stderr.puts "WARNING! i18n test skipeed because I18n not found"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selectable_attr_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.3.11
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-12-17 00:00:00 +09:00
12
+ date: 2010-01-14 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.3.5
53
+ version: 0.3.11
54
54
  version:
55
55
  description: selectable_attr_rails makes possible to use selectable_attr in rails application
56
56
  email: akima@gmail.com