selectable_attr_rails 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :minor: 3
3
- :patch: 7
2
+ :build:
4
3
  :major: 0
4
+ :minor: 3
5
+ :patch: 8
@@ -9,10 +9,38 @@ module SelectableAttrRails
9
9
  end
10
10
 
11
11
  module Entry
12
- attr_accessor :name_from_db
13
- def name
14
- @name_from_db || super
12
+
13
+ if defined?(I18n)
14
+ def name_from_db
15
+ @names_from_db ||= {}
16
+ @names_from_db[I18n.locale.to_s]
17
+ end
18
+
19
+ def name_from_db=(value)
20
+ @names_from_db ||= {}
21
+ @names_from_db[I18n.locale.to_s] = value
22
+ end
23
+
24
+ def name_with_from_db
25
+ name_from_db || name_without_from_db
26
+ end
27
+
28
+ else
29
+
30
+ attr_accessor :name_from_db
31
+ def name_with_from_db
32
+ @name_from_db || name_without_from_db
33
+ end
34
+
35
+ end
36
+
37
+ def self.extended(obj)
38
+ obj.instance_eval do
39
+ alias :name_without_from_db :name
40
+ alias :name :name_with_from_db
41
+ end
15
42
  end
43
+
16
44
  end
17
45
 
18
46
  module InstanceMethods
@@ -30,7 +58,7 @@ module SelectableAttrRails
30
58
  unless @original_entries
31
59
  @original_entries = @entries.dup
32
60
  @original_entries.each do |entry|
33
- entry.extend(SelectableAttrRails::DbLoadable::Entry)
61
+ entry.extend(SelectableAttrRails::DbLoadable::Entry) unless respond_to?(:name_from_db)
34
62
  end
35
63
  end
36
64
  records = nil
@@ -38,7 +66,8 @@ module SelectableAttrRails
38
66
  records = @sql_to_update.call
39
67
  else
40
68
  @connection ||= ActiveRecord::Base.connection
41
- records = @connection.select_rows(@sql_to_update)
69
+ sql = @sql_to_update.gsub(/\:locale/, I18n.locale.to_s.inspect)
70
+ records = @connection.select_rows(sql)
42
71
  end
43
72
 
44
73
  new_entries = []
@@ -48,6 +77,8 @@ module SelectableAttrRails
48
77
  new_entries << entry
49
78
  else
50
79
  entry = SelectableAttr::Enum::Entry.new(self, r.first, "entry_#{r.first}".to_sym, r.last)
80
+ entry.extend(SelectableAttrRails::DbLoadable::Entry)
81
+ entry.name_from_db = r.last
51
82
  new_entries << entry
52
83
  end
53
84
  end
@@ -2,6 +2,10 @@ module SelectableAttrRails::Helpers
2
2
  module RadioButtonGroupHelper
3
3
  class Builder < SelectableAttrRails::Helpers::AbstractSelectionBuilder
4
4
 
5
+ attr_reader :entry_hash_array
6
+ attr_reader :entry_hash
7
+ attr_accessor :radio_button_id
8
+
5
9
  def initialize(object, object_name, method, options, template)
6
10
  super(object, object_name, method, options, template)
7
11
  @entry_hash_array ||= enum_hash_array_from_class
@@ -26,7 +26,7 @@ module SelectableAttrRails::Helpers
26
26
 
27
27
  def single_enum_select(object_name, method, options = {}, html_options = {}, &block)
28
28
  options = update_enum_select_options(options, object_name, method)
29
- object = options.delete(:object)
29
+ object = options[:object] # options.delete(:object)
30
30
  base_name = options.delete(:base_name)
31
31
  entry_hash_array = options.delete(:entry_hash_array) || object.class.send("#{base_name}_hash_array")
32
32
  container = entry_hash_array.map{|hash| [hash[:name].to_s, hash[:id]]}
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.7
4
+ version: 0.3.8
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-10-19 00:00:00 +09:00
12
+ date: 2009-10-29 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency