virtus-localized 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c94bc7cbbc1d0ef5f77e2fbc9dbb8cf625f57159
4
- data.tar.gz: d7545c61768606335cc656556becb22a53a757d9
3
+ metadata.gz: 299fc7e7428bc14c45bc23a528540be2049a624f
4
+ data.tar.gz: eb43371c5408514c52e9dfd764e33367ea222468
5
5
  SHA512:
6
- metadata.gz: 3388c4512efb4e19703ded5a30119a88111c0952bd68201d6f7d748b6c0f3bbdb7f6050d98dbed0f88b6d7faa0e8b1f3987e8dd8b41624c00eb78b0403594fcf
7
- data.tar.gz: 4e9c0923a3d17905baa396eff43db65149786e44173e1fd2a143b95b76cb9931e0cf8267e0d300fbc3f25852ec6ae682057afc3b318c42ade5fa973114443482
6
+ metadata.gz: 49b183a67d0c95b759a7aedb4c83ad0bb8c3ecc9bc91e1ff37ab95d01e3845a17c8ac82b713bd32e7f043d18ebb8eb519ac42895b3b5ce3023a7ae7f57bd904e
7
+ data.tar.gz: 0b9a371b3c15e7978bbba76821c94b3555dcbfd6b5b138b8f7be25d82dfaab67568a9c9fc02ed80cd54d6056c31c7d1805f7c2f7904ac22e50ec996ca42f9311
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Virtus::Localized
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/virtus/localized`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status][travis-image]][travis-url]
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Virtus::Localized is an extension for [virtus][travis-url] that adds the `localized` feature. It's based on the `localized` feature of [MongoID][mongoID-url] and was requested via this [issue][issue-url]
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,13 +22,53 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ You need to require it first:
26
26
 
27
- ## Development
27
+ ```ruby
28
+ require 'virtus/localized'
29
+ ```
30
+
31
+ Then it gives you the following flag when definig the `attribute`:
32
+
33
+ ```ruby
34
+ class Post
35
+ include Virtus.model
36
+
37
+ attribute :title, String, localized: true
38
+ attribute :body, String, localized: true
39
+ end
40
+
41
+ ```
42
+
43
+ It uses the [i18n](https://github.com/svenfuchs/i18n) to detect the `locale` and creates an internal hash for the attribute:
44
+
45
+ ```ruby
46
+ post = Post.new(title: 'Hello', body: 'English')
47
+
48
+ p post.title
49
+ # => 'Hello'
28
50
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
51
+ p post.body
52
+ # => 'English'
30
53
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+ I18n.locale = :es
55
+
56
+ post.title = 'Hola'
57
+ post.body = 'Español'
58
+
59
+ p post.title
60
+ # => 'Hola'
61
+
62
+ p post.body
63
+ # => 'Español'
64
+
65
+ p post.instance_variable_get('@title')
66
+ # { "en" => "Hello", "es" => "Hola" }
67
+
68
+ p post.instance_variable_get('@body')
69
+ # { "en" => "English", "es" => "Español" }
70
+
71
+ ```
32
72
 
33
73
  ## Contributing
34
74
 
@@ -37,3 +77,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
37
77
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
78
  4. Push to the branch (`git push origin my-new-feature`)
39
79
  5. Create a new Pull Request
80
+
81
+ ## License
82
+
83
+ [MIT](LICENSE)
84
+
85
+ [travis-image]: https://travis-ci.org/XescuGC/virtus-localized.svg?branch=maste
86
+ [travis-url]: https://travis-ci.org/XescuGC/virtus-localized
87
+ [virtus-url]: https://github.com/solnic/virtus
88
+ [mongoID-url]: https://travis-ci.org/XescuGC/virtus-localized
89
+ [issue-url]: https://travis-ci.org/XescuGC/virtus-localized
90
+
@@ -1,5 +1,5 @@
1
1
  module Virtus
2
2
  module Localized
3
- VERSION = "0.1.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtus-localized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xescuGC