easy_translatable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b058f1009620ef66e0eb9a2425af27841e3f4d61
4
- data.tar.gz: 97066aa3b7af92612aff25f95896be71a0f70174
3
+ metadata.gz: 74b40eace2abda621f5019ea144a1e46f33977d3
4
+ data.tar.gz: 0ee0103de6ce639fbf75d1474eb864d12d5f57c4
5
5
  SHA512:
6
- metadata.gz: 29f96b7b1d821caafea24001ba52d15350527d3df865819a60b17cfafea5fa2aab40459c04be70935b624597ed8f90b68905c79ba2703474d72e9fc63625259e
7
- data.tar.gz: 40ddc1c5111c3b3d1ac02bf2d75d87e8349e24d043b0b345b361a28e804e227f122aa17f30e2c833eda46090b4e74b8dca7b929df4bc6084da11ea80b135444e
6
+ metadata.gz: 48b503b54a498d677c87df013a5fb7a46b2f42905b8be2d41c679f79a3c1dbda8403e2b92ce03f9085aefc48670312d971ea2b200c669c40ccab2961cd2b1806
7
+ data.tar.gz: d57355737118302f13d97a92dec4ddd79edcef183504f885e3884d79cb6907a3332aa1205186fee9f08a9d8c2d89e269e180a51a5ddb7c6edde5ad10317d1616
data/README.md CHANGED
@@ -17,4 +17,12 @@ When using bundler put this in your Gemfile:
17
17
 
18
18
  ```ruby
19
19
  gem 'easy_translatable', '~> 0.1.0'
20
- ```
20
+ ```
21
+
22
+ ## Todo
23
+
24
+ - Tests, tests and tests
25
+ - cleanup
26
+ - doc
27
+ - migration/model for translation table
28
+ - serialized attributes (JSON/YML)
@@ -47,7 +47,7 @@ module Translatable
47
47
  end
48
48
 
49
49
  def translate?
50
- !@translate_me.nil? && @translate_me = true
50
+ !@translate_me.nil? && @translate_me
51
51
  end
52
52
 
53
53
  def read_attribute(name, options = {})
@@ -11,29 +11,15 @@ module Translatable
11
11
  attr_names -= translated_attribute_names if defined?(translated_attribute_names)
12
12
 
13
13
  if attr_names.present?
14
- translation_class.instance_eval %{
15
- attr_accessible :#{attr_names.join(', :')}
16
- }
17
14
 
18
15
  attr_names.each do |attr_name|
19
- # Detect and apply serialization.
20
- serializer = self.serialized_attributes[attr_name.to_s]
21
- if serializer.present?
22
- if defined?(::ActiveRecord::Coders::YAMLColumn) &&
23
- serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
24
-
25
- serializer = serializer.object_class
26
- end
27
-
28
- translation_class.send :serialize, attr_name, serializer
29
- end
30
-
31
16
  # Create accessors for the attribute.
32
17
  translated_attr_accessor(attr_name)
33
18
  translations_accessor(attr_name)
34
19
 
35
20
  # Add attribute to the list.
36
21
  self.translated_attribute_names << attr_name
22
+ self.translated_serialized_attributes[attr_name] = options[:json] if options[:json]
37
23
  end
38
24
 
39
25
  Translatable.add_translatable self
@@ -58,15 +44,11 @@ module Translatable
58
44
  options[:foreign_key] ||= 'record_id'
59
45
  options[:conditions] ||= ''
60
46
 
61
- class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations
47
+ class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations, :translated_serialized_attributes
62
48
  self.translated_attribute_names = []
63
49
  self.translation_options = options
64
50
  self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
65
-
66
- # Alias original relation method so we can safely override it in ClassMethods.
67
- #class << self
68
- # alias relation_without_globalize relation
69
- #end
51
+ self.translated_serialized_attributes = Hash.new if options[:json]
70
52
 
71
53
  include InstanceMethods
72
54
  extend ClassMethods
data/lib/translatable.rb CHANGED
@@ -42,6 +42,10 @@ module Translatable
42
42
  else
43
43
  @@translatable[klass.name] = klass.translated_attribute_names
44
44
  end
45
+
46
+ unless klass.translated_serialized_attributes.nil?
47
+ @@translatable[klass.name].map!{ |attr| klass.translated_serialized_attributes.reject{|k,v| k != attr} }
48
+ end
45
49
  end
46
50
 
47
51
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_translatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Bonaud
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '3.0'
20
+ version: '3.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '3.0'
27
+ version: '3.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement