booletania 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17b4fb52dbb212b476970a5ddc26914d402d8e72
4
+ data.tar.gz: f8878973581469831d5fbdc91a95007e825f8c63
5
+ SHA512:
6
+ metadata.gz: d9877b985b92fcd66dccacd6544af6995d4638f074310ecbaed69d296343e54ac9fbcfc1de736af43dd2e7b65fdabb12a3705bc54c8880bc34d58e2d90c88f89
7
+ data.tar.gz: c9cd83aaaf0813f7d4d892e3a8201f5926ed5b9c60a11b034b7572d6eca886f9729addde35d44fa30b3a46bdf66402fccb95f24d7a8fd5adb709eee34a2a2292
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.sw*
16
+ .rspec
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in booletania.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 ryoff
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Booletania
2
+
3
+ translating AR booleans in I18n files
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'booletania'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install booletania
20
+
21
+ ## Usage
22
+
23
+ migration
24
+
25
+ ````ruby
26
+ create_table(:invitations) do |t|
27
+ t.boolean :accepted
28
+ end
29
+ ```
30
+
31
+ model
32
+
33
+ ````ruby
34
+ class Invitation < ActiveRecord::Base
35
+ include Booletania
36
+ end
37
+ ```
38
+
39
+ i18n
40
+
41
+ ````ruby
42
+ ja:
43
+ booletania:
44
+ invitation:
45
+ accepted:
46
+ 'true': 承諾
47
+ 'false': 拒否
48
+ ```
49
+
50
+ - why need to quote?
51
+ - [see also]
52
+ - http://yaml.org/type/bool.html
53
+ - https://groups.google.com/forum/#!topic/rails-i18n/aL-Ed1Y1KGo
54
+
55
+ ````ruby
56
+ invitation.accepted = true
57
+ invitation.accepted_text # => "承諾"
58
+
59
+ invitation.accepted = false
60
+ invitation.accepted_text # => "拒否"
61
+
62
+ I18n.locale = :en
63
+ invitation.accepted_text # => "deny"
64
+
65
+ invitation.accepted = true
66
+ invitation.accepted_text # => "accept"
67
+ ```
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it ( https://github.com/[my-github-username]/booletania/fork )
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'booletania/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "booletania"
8
+ spec.version = Booletania::VERSION
9
+ spec.authors = ["ryoff"]
10
+ spec.email = ["ryoffes@gmail.com"]
11
+ spec.summary = %q{translating AR booleans in I18n files}
12
+ spec.description = %q{translating AR booleans in I18n files}
13
+ spec.homepage = "https://github.com/ryoff/booletania"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activerecord", ">= 4.0"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "sqlite3"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry-byebug"
28
+ end
@@ -0,0 +1,14 @@
1
+ module Booletania
2
+ class Attribute
3
+ def self.define_methods!(klass, boolean_columns)
4
+ boolean_columns.each do |boolean_column|
5
+ klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
6
+ def #{boolean_column.name}_text
7
+ # http://yaml.org/type/bool.html
8
+ I18n.t "booletania.#{klass.name.underscore}.#{boolean_column.name}." + #{boolean_column.name}.__send__(:to_s), default: #{boolean_column.name}.__send__(:to_s)
9
+ end
10
+ RUBY
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Booletania
2
+ VERSION = "0.0.1"
3
+ end
data/lib/booletania.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "booletania/version"
2
+ require "booletania/attribute"
3
+
4
+ module Booletania
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ fail ArgumentError, "booletania only support ActiveRecord" unless ancestors.include? ActiveRecord::Base
9
+ fail ArgumentError, "not found .columns method" unless respond_to? :columns
10
+
11
+ Attribute.define_methods!(self, columns.select{ |column| column.type == :boolean })
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ class Invitation < ActiveRecord::Base
4
+ include Booletania
5
+ end
6
+
7
+ # not AR
8
+ class NotActiveRecord
9
+ def initialize
10
+ self.class.__send__(:include, Booletania)
11
+ end
12
+ end
13
+
14
+ describe Booletania do
15
+ it 'has a version number' do
16
+ expect(Booletania::VERSION).not_to be nil
17
+ end
18
+
19
+ context "don't extend AR" do
20
+ subject { NotActiveRecord.new }
21
+
22
+ it 'raise ArgumentError' do
23
+ expect { subject }.to raise_error(ArgumentError)
24
+ end
25
+ end
26
+
27
+ describe "_text" do
28
+ let!(:invitation) { Invitation.create(accepted: accepted) }
29
+ after { Invitation.delete_all }
30
+
31
+ subject { invitation.accepted_text }
32
+
33
+ context "lang is ja" do
34
+ before { I18n.locale = :ja }
35
+
36
+ context "column is true" do
37
+ let(:accepted) { true }
38
+
39
+ it { is_expected.to eq '承諾' }
40
+ end
41
+
42
+ context "column is false" do
43
+ let(:accepted) { false }
44
+
45
+ it { is_expected.to eq '拒否' }
46
+ end
47
+ end
48
+
49
+ context "lang is en" do
50
+ before { I18n.locale = :en }
51
+
52
+ context "column is true" do
53
+ let(:accepted) { true }
54
+
55
+ it { is_expected.to eq 'accept' }
56
+ end
57
+
58
+ context "column is false" do
59
+ let(:accepted) { false }
60
+
61
+ it { is_expected.to eq 'deny' }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,6 @@
1
+ en:
2
+ booletania:
3
+ invitation:
4
+ accepted:
5
+ 'true': accept
6
+ 'false': deny
@@ -0,0 +1,6 @@
1
+ ja:
2
+ booletania:
3
+ invitation:
4
+ accepted:
5
+ 'true': 承諾
6
+ 'false': 拒否
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+ require 'pry'
3
+ require 'pry-byebug'
4
+ require 'bundler/setup'
5
+ Bundler.require
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
7
+
8
+ I18n.load_path += Dir["#{File.dirname(__FILE__)}/fixtures/locales/*.yml"]
9
+ I18n.enforce_available_locales = false
10
+
11
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
12
+ require 'booletania'
@@ -0,0 +1,13 @@
1
+ ActiveRecord::Base.configurations = {'test' => {adapter: 'sqlite3', database: ':memory:'}}
2
+ ActiveRecord::Base.establish_connection :test
3
+
4
+ class CreateAllTables < ActiveRecord::Migration
5
+ def self.up
6
+ create_table(:invitations) do |t|
7
+ t.boolean :accepted
8
+ end
9
+ end
10
+ end
11
+
12
+ ActiveRecord::Migration.verbose = false
13
+ CreateAllTables.up
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: booletania
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ryoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: translating AR booleans in I18n files
112
+ email:
113
+ - ryoffes@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - booletania.gemspec
126
+ - lib/booletania.rb
127
+ - lib/booletania/attribute.rb
128
+ - lib/booletania/version.rb
129
+ - spec/booletania_spec.rb
130
+ - spec/fixtures/locales/en.yml
131
+ - spec/fixtures/locales/ja.yml
132
+ - spec/spec_helper.rb
133
+ - spec/support/setup_database.rb
134
+ homepage: https://github.com/ryoff/booletania
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.0
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: translating AR booleans in I18n files
158
+ test_files:
159
+ - spec/booletania_spec.rb
160
+ - spec/fixtures/locales/en.yml
161
+ - spec/fixtures/locales/ja.yml
162
+ - spec/spec_helper.rb
163
+ - spec/support/setup_database.rb