enum_i18n_help 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: a05fa1a83bcf0b57dc7b069d26e04f00adc5601d
4
- data.tar.gz: b9c44c6df17fe122a4a3526dfa04ecf32019377d
2
+ SHA256:
3
+ metadata.gz: c49dd954210f837a832afee83804d1cb2e176042e854519d75f4730ce5f9d627
4
+ data.tar.gz: 6c1d788a23e159f929eec6e1ee3c55d90bf1cf85cda76a2e83fe5d0d100d961e
5
5
  SHA512:
6
- metadata.gz: 0da402a997a611d409cf4d5e73309f8870f48cab7d5bb24d056cb6a6c95269af84fa8d84b27365b1e818b7fee1ba314a6394dbb0ce9f73d69ef277c2b9e6e7ac
7
- data.tar.gz: 5ae6dadd26a445f34f20d437cf29798a60ed3c3dfd8a7faf62608854e353235386908d14a78a12968238b1df60a9181c98b2d0c25cf4bb478001fd6358739932
6
+ metadata.gz: 486374faf6157452787409453fc92346924a5b5bde0e05d99fa008db3c7b350d257b31971eb1c4bfd957a6fb2b2d4343c82be038809a5c16e78c44e42b4692eb
7
+ data.tar.gz: d8ec3e6586a252c4bf02809c0d5397fd79a34a0112422b7c2488a0263e94ef7e38e440b2be83275119ebc50040ac355d35fbcd8b9f613011cbb9dd763ac36da4
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.9
4
+ - 2.3.5
5
+ - 2.4.3
6
+ - 2.5.0
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler -v 1.16.1
10
+ cache: bundler
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # EnumI18nHelp
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/enum_i18n_help`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Help ActiveRecord::Enum feature to work with I18n.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ added a new Test::Unit to the existing EnumHelp gem and changed the namespace of I18n.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,22 +22,65 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ model
26
26
 
27
- ## Development
27
+ ```ruby
28
+ class User < ActiveRecord::Base
29
+ enum role: { manager: 1, member: 2 }
30
+ end
31
+ ```
28
32
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+ I18n
30
34
 
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+ ```ruby
36
+ ja:
37
+ activerecord:
38
+ attributes:
39
+ user/role:
40
+ manager: 管理者
41
+ member: 一般
42
+ ```
32
43
 
33
- ## Contributing
44
+ ```ruby
45
+ en:
46
+ activerecord:
47
+ attributes:
48
+ user/role:
49
+ manager: Manager
50
+ member: Member
51
+ ```
34
52
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enum_i18n_help. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
53
+ ### enum_column_text
36
54
 
37
- ## License
55
+ ```ruby
56
+ user = User.first
57
+ user.role
58
+ => "manager"
59
+ user.role_text
60
+ => "管理者"
61
+ ```
38
62
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+ change locale
40
64
 
41
- ## Code of Conduct
65
+ ```ruby
66
+ I18n.locale = :en
67
+ user.role
68
+ => "manager"
69
+ user.role_text
70
+ => "Manager"
71
+ ```
72
+
73
+ ### enum_column_options
74
+
75
+ ```ruby
76
+ User.role_options
77
+ => [["管理者", :manager], ["一般", :member]]
78
+ ```
79
+
80
+ ## Contributing
42
81
 
43
- Everyone interacting in the EnumI18nHelp project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/enum_i18n_help/blob/master/CODE_OF_CONDUCT.md).
82
+ 1. Fork it ( https://github.com/ShuheiTsuji/enum_i18n_help )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create new Pull Request
@@ -2,9 +2,16 @@ module EnumI18nHelp
2
2
  module EnumI18n
3
3
  def enum(definitions)
4
4
  super(definitions)
5
- definitions.each do |key, value|
5
+ # super has defined enum.
6
+ # So defined_enums are available!
7
+ #
8
+ # To avoid defining methods multiple times,
9
+ # slices hash to get enums called this time.
10
+ #
11
+ # Be careful not to destroy defined_enum, such as using merge!
12
+ defined_enums.slice(*definitions.keys.map(&:to_s)).each_pair do |key, value|
6
13
  EnumAttribute.define_text_method!(self, key)
7
- EnumAttribute.define_options_method!(self, key, value)
14
+ EnumAttribute.define_options_method!(self, key, value.symbolize_keys)
8
15
  end
9
16
  end
10
17
  end
@@ -20,6 +27,7 @@ module EnumI18nHelp
20
27
  METHOD
21
28
  end
22
29
 
30
+ # This method assume that attr_value is a symbolized hash
23
31
  def define_options_method!(klass, attr_name, attr_value)
24
32
  attr_value_hash = attr_value.keys.map { |key| [key, key.to_s.humanize] }.to_h
25
33
 
@@ -1,3 +1,3 @@
1
1
  module EnumI18nHelp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_i18n_help
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
  - ShuheiTsuji
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-09 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -131,6 +131,7 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
133
  - ".rspec"
134
+ - ".travis.yml"
134
135
  - CODE_OF_CONDUCT.md
135
136
  - Gemfile
136
137
  - LICENSE.txt
@@ -161,8 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  - !ruby/object:Gem::Version
162
163
  version: '0'
163
164
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.5.1
165
+ rubygems_version: 3.0.3
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: Enum attributes with I18n and ActiveRecord support