booletania 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/booletania/attribute.rb +3 -3
- data/lib/booletania/method.rb +8 -8
- data/lib/booletania/version.rb +1 -1
- data/lib/booletania.rb +10 -6
- data/spec/booletania_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77356e56bd6140dae014c54742488de312944f77
|
4
|
+
data.tar.gz: 181cfe433cb7e79e6d097688ba3025bdfda1e7e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10b25727f3799336e225d391ecfe5d83a105863ea8c81a9d3d600ebf9ca86ff1631f053ffdb034e4205d1135ade73e9021e04af93e08228f60ed630bc57f0132
|
7
|
+
data.tar.gz: 196e4761b8137046de0ebd00467f285a5e6985517f2537a41415c93686f49530b8ccdbbdff614b5246d1dc56871b2d8ef6787b7e98de0c795e9616b956671127
|
data/README.md
CHANGED
data/lib/booletania/attribute.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Booletania
|
2
2
|
class Attribute
|
3
3
|
class << self
|
4
|
-
def define_methods!(klass,
|
5
|
-
|
6
|
-
method_obj = Booletania::Method.new(klass,
|
4
|
+
def define_methods!(klass, boolean_column_names)
|
5
|
+
boolean_column_names.each do |boolean_column_name|
|
6
|
+
method_obj = Booletania::Method.new(klass, boolean_column_name.to_s)
|
7
7
|
|
8
8
|
define_attribute_text(method_obj)
|
9
9
|
|
data/lib/booletania/method.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module Booletania
|
2
2
|
class Method
|
3
|
-
attr_reader :klass, :
|
3
|
+
attr_reader :klass, :boolean_column_name
|
4
4
|
|
5
|
-
def initialize(klass,
|
5
|
+
def initialize(klass, boolean_column_name)
|
6
6
|
@klass = klass
|
7
|
-
@
|
7
|
+
@boolean_column_name = boolean_column_name
|
8
8
|
end
|
9
9
|
|
10
10
|
def _text
|
11
11
|
i18n_true_keys = i18n_keys('true') + [true.to_s.humanize]
|
12
12
|
i18n_false_keys = i18n_keys('false') + [false.to_s.humanize]
|
13
13
|
<<-RUBY
|
14
|
-
def #{
|
15
|
-
keys = #{
|
14
|
+
def #{boolean_column_name}_text
|
15
|
+
keys = #{boolean_column_name}? ? #{i18n_true_keys} : #{i18n_false_keys}
|
16
16
|
|
17
17
|
I18n.t(keys[0], default: keys[1..-1])
|
18
18
|
end
|
@@ -22,7 +22,7 @@ module Booletania
|
|
22
22
|
def _options
|
23
23
|
path_keys = i18n_path_keys + [{}]
|
24
24
|
<<-RUBY
|
25
|
-
def #{
|
25
|
+
def #{boolean_column_name}_options
|
26
26
|
I18n.t("#{path_keys[0]}", default: #{path_keys[1..-1]}).invert.map { |k, v| [k, v.to_b] }
|
27
27
|
end
|
28
28
|
RUBY
|
@@ -58,12 +58,12 @@ module Booletania
|
|
58
58
|
|
59
59
|
# For example, :booletania.invitation.accepted
|
60
60
|
def booletania_i18n_path_key
|
61
|
-
:"booletania.#{klass.name.underscore}.#{
|
61
|
+
:"booletania.#{klass.name.underscore}.#{boolean_column_name}"
|
62
62
|
end
|
63
63
|
|
64
64
|
# For example, :activerecord.attributes.invitation/accepted
|
65
65
|
def activerecord_i18n_path_key
|
66
|
-
:"activerecord.attributes.#{klass.name.underscore}/#{
|
66
|
+
:"activerecord.attributes.#{klass.name.underscore}/#{boolean_column_name}"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/booletania/version.rb
CHANGED
data/lib/booletania.rb
CHANGED
@@ -3,12 +3,16 @@ require "booletania/method"
|
|
3
3
|
require "booletania/attribute"
|
4
4
|
|
5
5
|
module Booletania
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
base.class_eval do
|
9
|
+
raise ArgumentError, "booletania only support ActiveRecord" unless ancestors.include? ActiveRecord::Base
|
10
|
+
end
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
+
module ClassMethods
|
14
|
+
def booletania_columns(*columns)
|
15
|
+
Booletania::Attribute.define_methods!(self, columns)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
data/spec/booletania_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booletania
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|