ar_serialized_array 0.1.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +2 -0
  3. data/README.markdown +57 -0
  4. data/Rakefile +68 -5
  5. data/VERSION +1 -1
  6. data/cache/file_data_provider/countries-AF.txt +246 -0
  7. data/cache/file_data_provider/countries-AM.txt +246 -0
  8. data/cache/file_data_provider/countries-AR.txt +246 -0
  9. data/cache/file_data_provider/countries-AZ.txt +246 -0
  10. data/cache/file_data_provider/countries-BE.txt +246 -0
  11. data/cache/file_data_provider/countries-BG.txt +246 -0
  12. data/cache/file_data_provider/countries-BN.txt +246 -0
  13. data/cache/file_data_provider/countries-BR.txt +246 -0
  14. data/cache/file_data_provider/countries-BS.txt +246 -0
  15. data/cache/file_data_provider/countries-CA.txt +246 -0
  16. data/cache/file_data_provider/countries-CS.txt +246 -0
  17. data/cache/file_data_provider/countries-CY.txt +246 -0
  18. data/cache/file_data_provider/countries-DA.txt +246 -0
  19. data/cache/file_data_provider/countries-DE.txt +246 -0
  20. data/cache/file_data_provider/countries-DZ.txt +246 -0
  21. data/cache/file_data_provider/countries-EL.txt +246 -0
  22. data/cache/file_data_provider/countries-EN.txt +246 -0
  23. data/cache/file_data_provider/countries-EO.txt +246 -0
  24. data/cache/file_data_provider/countries-ES.txt +246 -0
  25. data/cache/file_data_provider/countries-ET.txt +246 -0
  26. data/cache/file_data_provider/countries-EU.txt +246 -0
  27. data/cache/file_data_provider/countries-FA.txt +246 -0
  28. data/cache/file_data_provider/countries-FI.txt +246 -0
  29. data/cache/file_data_provider/countries-FO.txt +246 -0
  30. data/cache/file_data_provider/countries-FR.txt +246 -0
  31. data/cache/file_data_provider/countries-GA.txt +246 -0
  32. data/cache/file_data_provider/countries-GL.txt +246 -0
  33. data/cache/file_data_provider/countries-GU.txt +246 -0
  34. data/cache/file_data_provider/countries-HE.txt +246 -0
  35. data/cache/file_data_provider/countries-HI.txt +246 -0
  36. data/cache/file_data_provider/countries-HR.txt +246 -0
  37. data/cache/file_data_provider/countries-HU.txt +246 -0
  38. data/cache/file_data_provider/countries-HY.txt +246 -0
  39. data/cache/file_data_provider/countries-ID.txt +246 -0
  40. data/cache/file_data_provider/countries-IS.txt +246 -0
  41. data/cache/file_data_provider/countries-IT.txt +246 -0
  42. data/cache/file_data_provider/countries-JA.txt +246 -0
  43. data/cache/file_data_provider/countries-KA.txt +246 -0
  44. data/cache/file_data_provider/countries-KK.txt +246 -0
  45. data/cache/file_data_provider/countries-KM.txt +246 -0
  46. data/cache/file_data_provider/countries-KN.txt +246 -0
  47. data/cache/file_data_provider/countries-KO.txt +246 -0
  48. data/cache/file_data_provider/countries-KU.txt +246 -0
  49. data/cache/file_data_provider/countries-LT.txt +246 -0
  50. data/cache/file_data_provider/countries-LV.txt +246 -0
  51. data/cache/file_data_provider/countries-MI.txt +246 -0
  52. data/cache/file_data_provider/countries-MK.txt +246 -0
  53. data/cache/file_data_provider/countries-ML.txt +246 -0
  54. data/cache/file_data_provider/countries-MN.txt +246 -0
  55. data/cache/file_data_provider/countries-MR.txt +246 -0
  56. data/cache/file_data_provider/countries-MS.txt +246 -0
  57. data/cache/file_data_provider/countries-MT.txt +246 -0
  58. data/cache/file_data_provider/countries-NB.txt +246 -0
  59. data/cache/file_data_provider/countries-NE.txt +246 -0
  60. data/cache/file_data_provider/countries-NL.txt +246 -0
  61. data/cache/file_data_provider/countries-NN.txt +246 -0
  62. data/cache/file_data_provider/countries-OC.txt +246 -0
  63. data/cache/file_data_provider/countries-PA.txt +246 -0
  64. data/cache/file_data_provider/countries-PL.txt +246 -0
  65. data/cache/file_data_provider/countries-PS.txt +246 -0
  66. data/cache/file_data_provider/countries-PT.txt +246 -0
  67. data/cache/file_data_provider/countries-RO.txt +246 -0
  68. data/cache/file_data_provider/countries-RU.txt +246 -0
  69. data/cache/file_data_provider/countries-RW.txt +246 -0
  70. data/cache/file_data_provider/countries-SK.txt +246 -0
  71. data/cache/file_data_provider/countries-SL.txt +246 -0
  72. data/cache/file_data_provider/countries-SO.txt +246 -0
  73. data/cache/file_data_provider/countries-SQ.txt +246 -0
  74. data/cache/file_data_provider/countries-SR.txt +246 -0
  75. data/cache/file_data_provider/countries-SV.txt +246 -0
  76. data/cache/file_data_provider/countries-SW.txt +246 -0
  77. data/cache/file_data_provider/countries-TA.txt +246 -0
  78. data/cache/file_data_provider/countries-TH.txt +246 -0
  79. data/cache/file_data_provider/countries-TI.txt +246 -0
  80. data/cache/file_data_provider/countries-TK.txt +246 -0
  81. data/cache/file_data_provider/countries-TL.txt +246 -0
  82. data/cache/file_data_provider/countries-TR.txt +246 -0
  83. data/cache/file_data_provider/countries-TT.txt +246 -0
  84. data/cache/file_data_provider/countries-UK.txt +246 -0
  85. data/cache/file_data_provider/countries-VE.txt +246 -0
  86. data/cache/file_data_provider/countries-VI.txt +246 -0
  87. data/cache/file_data_provider/countries-WA.txt +246 -0
  88. data/cache/file_data_provider/countries-WO.txt +246 -0
  89. data/cache/file_data_provider/countries-XH.txt +246 -0
  90. data/cache/file_data_provider/countries-ZU.txt +246 -0
  91. data/cache/file_data_provider/languages-AF.txt +185 -0
  92. data/cache/file_data_provider/languages-AM.txt +185 -0
  93. data/cache/file_data_provider/languages-AR.txt +185 -0
  94. data/cache/file_data_provider/languages-AZ.txt +185 -0
  95. data/cache/file_data_provider/languages-BE.txt +185 -0
  96. data/cache/file_data_provider/languages-BG.txt +185 -0
  97. data/cache/file_data_provider/languages-BR.txt +185 -0
  98. data/cache/file_data_provider/languages-BS.txt +185 -0
  99. data/cache/file_data_provider/languages-CA.txt +185 -0
  100. data/cache/file_data_provider/languages-CS.txt +185 -0
  101. data/cache/file_data_provider/languages-CY.txt +185 -0
  102. data/cache/file_data_provider/languages-DA.txt +185 -0
  103. data/cache/file_data_provider/languages-DE.txt +185 -0
  104. data/cache/file_data_provider/languages-EL.txt +185 -0
  105. data/cache/file_data_provider/languages-EN.txt +185 -0
  106. data/cache/file_data_provider/languages-EO.txt +185 -0
  107. data/cache/file_data_provider/languages-ES.txt +185 -0
  108. data/cache/file_data_provider/languages-ET.txt +185 -0
  109. data/cache/file_data_provider/languages-EU.txt +185 -0
  110. data/cache/file_data_provider/languages-FA.txt +185 -0
  111. data/cache/file_data_provider/languages-FI.txt +185 -0
  112. data/cache/file_data_provider/languages-FR.txt +185 -0
  113. data/cache/file_data_provider/languages-GA.txt +185 -0
  114. data/cache/file_data_provider/languages-GL.txt +185 -0
  115. data/cache/file_data_provider/languages-HE.txt +185 -0
  116. data/cache/file_data_provider/languages-HI.txt +185 -0
  117. data/cache/file_data_provider/languages-HR.txt +185 -0
  118. data/cache/file_data_provider/languages-HU.txt +185 -0
  119. data/cache/file_data_provider/languages-ID.txt +185 -0
  120. data/cache/file_data_provider/languages-IS.txt +185 -0
  121. data/cache/file_data_provider/languages-IT.txt +185 -0
  122. data/cache/file_data_provider/languages-JA.txt +185 -0
  123. data/cache/file_data_provider/languages-KO.txt +185 -0
  124. data/cache/file_data_provider/languages-LT.txt +185 -0
  125. data/cache/file_data_provider/languages-LV.txt +185 -0
  126. data/cache/file_data_provider/languages-MI.txt +185 -0
  127. data/cache/file_data_provider/languages-MK.txt +185 -0
  128. data/cache/file_data_provider/languages-MN.txt +185 -0
  129. data/cache/file_data_provider/languages-MR.txt +185 -0
  130. data/cache/file_data_provider/languages-MS.txt +185 -0
  131. data/cache/file_data_provider/languages-MT.txt +185 -0
  132. data/cache/file_data_provider/languages-NB.txt +185 -0
  133. data/cache/file_data_provider/languages-NL.txt +185 -0
  134. data/cache/file_data_provider/languages-NN.txt +185 -0
  135. data/cache/file_data_provider/languages-OC.txt +185 -0
  136. data/cache/file_data_provider/languages-PL.txt +185 -0
  137. data/cache/file_data_provider/languages-PS.txt +185 -0
  138. data/cache/file_data_provider/languages-PT.txt +185 -0
  139. data/cache/file_data_provider/languages-RO.txt +185 -0
  140. data/cache/file_data_provider/languages-RU.txt +185 -0
  141. data/cache/file_data_provider/languages-RW.txt +185 -0
  142. data/cache/file_data_provider/languages-SK.txt +185 -0
  143. data/cache/file_data_provider/languages-SL.txt +185 -0
  144. data/cache/file_data_provider/languages-SR.txt +185 -0
  145. data/cache/file_data_provider/languages-SV.txt +185 -0
  146. data/cache/file_data_provider/languages-TA.txt +185 -0
  147. data/cache/file_data_provider/languages-TH.txt +185 -0
  148. data/cache/file_data_provider/languages-TI.txt +185 -0
  149. data/cache/file_data_provider/languages-TR.txt +185 -0
  150. data/cache/file_data_provider/languages-TT.txt +185 -0
  151. data/cache/file_data_provider/languages-UK.txt +185 -0
  152. data/cache/file_data_provider/languages-VE.txt +185 -0
  153. data/cache/file_data_provider/languages-VI.txt +185 -0
  154. data/cache/file_data_provider/languages-WA.txt +185 -0
  155. data/cache/file_data_provider/languages-XH.txt +185 -0
  156. data/cache/file_data_provider/languages-ZU.txt +185 -0
  157. data/example_output/all_names_for_DE.txt +85 -0
  158. data/example_output/all_names_for_FR.txt +85 -0
  159. data/example_output/all_names_for_GB.txt +85 -0
  160. data/example_output/all_names_for_US.txt +85 -0
  161. data/i18n_data.gemspec +31 -0
  162. data/lib/i18n_data/file_data_provider.rb +56 -0
  163. data/lib/i18n_data/live_data_provider.rb +97 -0
  164. data/lib/i18n_data.rb +34 -0
  165. data/spec/i18n_data/file_data_provider_spec.rb +23 -0
  166. data/spec/i18n_data/live_data_provider_spec.rb +44 -0
  167. data/spec/i18n_data_spec.rb +101 -0
  168. data/spec/spec_helper.rb +2 -4
  169. metadata +183 -39
  170. data/Readme.md +0 -50
  171. data/ar_serialized_array.gemspec +0 -47
  172. data/init.rb +0 -1
  173. data/lib/ar_serialized_array.rb +0 -37
  174. data/spec/ar_serialized_array_spec.rb +0 -84
  175. data/spec/setup_test_model.rb +0 -28
@@ -1,37 +0,0 @@
1
- require 'active_record'
2
-
3
- module ARSerializedArray
4
- VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
5
-
6
- def serialized_array(attr_name, options={})
7
- options[:on_set] ||= lambda{|x|x}
8
-
9
- # getter
10
- define_method attr_name do
11
- YAML.load(read_attribute(attr_name).to_s) || []
12
- end
13
-
14
- # setter
15
- define_method "#{attr_name}=" do |value|
16
- value = options[:on_set].call(value) || []
17
- raise "Expected an Array, got: #{value.inspect}" unless value.is_a? Array
18
- value = (value.empty? ? nil : value.to_yaml)
19
- write_attribute attr_name, value
20
- end
21
-
22
- # accessors e.g. xxx_as_text
23
- if options[:accessor]
24
- #getter
25
- define_method options[:accessor] do
26
- send(attr_name) * ", "
27
- end
28
-
29
- #setter
30
- define_method "#{options[:accessor]}=" do |value|
31
- send "#{attr_name}=", value.to_s.split(',').reject(&:blank?).map(&:strip)
32
- end
33
- end
34
- end
35
- end
36
-
37
- ActiveRecord::Base.send(:extend, ARSerializedArray)
@@ -1,84 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- describe 'ar_serialized_array' do
4
- describe 'basics' do
5
- it "is an empty array by default" do
6
- UserPlain.new.product_ids.should == []
7
- end
8
-
9
- it "serializes on set" do
10
- user = UserPlain.create!(:product_ids => [1, 2])
11
- UserPlain.find(user.id).product_ids.should == [1, 2]
12
- end
13
-
14
- it "can save an empty array" do
15
- user = UserPlain.create!(:product_ids => [])
16
- UserPlain.find(user.id).product_ids.should == []
17
- end
18
-
19
- it "can save nil" do
20
- user = UserPlain.create!(:product_ids => nil)
21
- UserPlain.find(user.id).product_ids.should == []
22
- end
23
-
24
- it "stores nil when nil is saved" do
25
- user = UserPlain.create!(:product_ids => nil)
26
- UserPlain.first(:conditions => {:id => user.id, :product_ids => nil}).should == user
27
- end
28
-
29
- it "stores empty arrays as NULL" do
30
- user = UserPlain.create!(:product_ids => [])
31
- UserPlain.first(:conditions => {:id => user.id, :product_ids => nil}).should == user
32
- end
33
-
34
- it "can search by array" do
35
- user = UserPlain.create!(:product_ids => [1])
36
- UserPlain.first(:conditions => {:id => user.id, :product_ids => [1].to_yaml}).should == user
37
- end
38
-
39
- it "raises when non-array is given" do
40
- lambda{ UserPlain.create!(:product_ids => '') }.should raise_error
41
- end
42
- end
43
-
44
- describe 'with accessor' do
45
- it "can access the array as text" do
46
- UserWithAccessor.new(:product_ids => [1,2,3]).product_ids_as_text.should == '1, 2, 3'
47
- end
48
-
49
- it "can set arrays via text" do
50
- UserWithAccessor.new(:product_ids_as_text => '1, 2, 3').product_ids.should == ['1','2','3']
51
- end
52
-
53
- it "is symetric" do
54
- text = '1, 2, 3'
55
- UserWithAccessor.new(:product_ids_as_text => text).product_ids_as_text.should == text
56
- end
57
-
58
- it "accepts nil as empty" do
59
- UserWithAccessor.new(:product_ids_as_text => nil).product_ids.should == []
60
- end
61
-
62
- it "is blank when unset" do
63
- UserWithAccessor.new.product_ids_as_text.should == ''
64
- end
65
-
66
- it "is blank when empty" do
67
- UserWithAccessor.new(:product_ids => []).product_ids_as_text.should == ''
68
- end
69
- end
70
-
71
- describe 'with on_set' do
72
- it "is used when storing normally" do
73
- User.new(:product_ids => ['1','2','2']).product_ids.should == [1,2]
74
- end
75
-
76
- it "is used when storing through accessor" do
77
- User.new(:product_ids_as_text => '1,2,2').product_ids.should == [1,2]
78
- end
79
- end
80
-
81
- it "has a VERSION" do
82
- ARSerializedArray::VERSION.should =~ /^\d+\.\d+\.\d+$/
83
- end
84
- end
@@ -1,28 +0,0 @@
1
- # connect
2
- ActiveRecord::Base.establish_connection(
3
- :adapter => "sqlite3",
4
- :database => ":memory:"
5
- )
6
-
7
- # create tables
8
- ActiveRecord::Schema.define(:version => 1) do
9
- create_table :users do |t|
10
- t.string :product_ids
11
- end
12
- end
13
-
14
- # create models
15
- class User < ActiveRecord::Base
16
- serialized_array :product_ids, :accessor => :product_ids_as_text, :on_set=>lambda{|x| x.map(&:to_i).uniq}
17
- end
18
-
19
- class UserWithAccessor < ActiveRecord::Base
20
- self.table_name = 'users'
21
- serialized_array :product_ids, :accessor => :product_ids_as_text
22
- end
23
-
24
-
25
- class UserPlain < ActiveRecord::Base
26
- self.table_name = 'users'
27
- serialized_array :product_ids
28
- end