class Booletania::Method
Attributes
boolean_column_name[R]
klass[R]
Public Class Methods
new(klass, boolean_column_name)
click to toggle source
# File lib/booletania/method.rb, line 5 def initialize(klass, boolean_column_name) @klass = klass @boolean_column_name = boolean_column_name end
Public Instance Methods
_options()
click to toggle source
# File lib/booletania/method.rb, line 22 def _options path_keys = i18n_path_keys + [{}] <<-RUBY def #{boolean_column_name}_options I18n.t("#{path_keys[0]}", default: #{path_keys[1..-1]}).invert.map { |k, v| [k, v.to_b] } end RUBY end
_text()
click to toggle source
# File lib/booletania/method.rb, line 10 def _text i18n_true_keys = i18n_keys('true') + [true.to_s.humanize] i18n_false_keys = i18n_keys('false') + [false.to_s.humanize] <<-RUBY def #{boolean_column_name}_text keys = #{boolean_column_name}? ? #{i18n_true_keys} : #{i18n_false_keys} I18n.t(keys[0], default: keys[1..-1]) end RUBY end
Private Instance Methods
activerecord_i18n_path_key()
click to toggle source
For example, :activerecord.attributes.invitation/accepted
# File lib/booletania/method.rb, line 65 def activerecord_i18n_path_key :"activerecord.attributes.#{klass.name.underscore}/#{boolean_column_name}" end
booletania_i18n_path_key()
click to toggle source
For example, :booletania.invitation.accepted
# File lib/booletania/method.rb, line 60 def booletania_i18n_path_key :"booletania.#{klass.name.underscore}.#{boolean_column_name}" end
i18n_keys(true_or_false)
click to toggle source
For example,
[ :booletania.invitation.accepted.true, :activerecord.attributes.invitation/accepted.true ]
For example,
[ :booletania.invitation.accepted.false, :activerecord.attributes.invitation/accepted.false ]
# File lib/booletania/method.rb, line 43 def i18n_keys(true_or_false) i18n_path_keys.map do |i18n_path_key| (i18n_path_key.to_s + '.' + true_or_false.to_b.to_s).to_sym end end
i18n_path_keys()
click to toggle source
# File lib/booletania/method.rb, line 49 def i18n_path_keys @i18n_path_keys ||= begin [].tap do |list| list << booletania_i18n_path_key list << activerecord_i18n_path_key list end end end