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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ede554f41aa09745752edb4854169d4963e1ed95
4
- data.tar.gz: 5a30b3dafe3f9c28f9219ada50ac9010e0b5fdde
3
+ metadata.gz: 77356e56bd6140dae014c54742488de312944f77
4
+ data.tar.gz: 181cfe433cb7e79e6d097688ba3025bdfda1e7e2
5
5
  SHA512:
6
- metadata.gz: 7f21d26ce0ae7bad0621cd7845387ab7cfa14d808d49a08a61650385d358f9f851ff5388503f49eef44e3db7bce76362f830091f985ea6a61ae399f65ee45da0
7
- data.tar.gz: aca04acd22d101420233411e5cd15fe5c5e9f476b7b7a45622b3d48ba19c3f9b219b53bfe7e956e5b3288425335d8800e5d980bd60787316b1c49d85c86b9a4e
6
+ metadata.gz: 10b25727f3799336e225d391ecfe5d83a105863ea8c81a9d3d600ebf9ca86ff1631f053ffdb034e4205d1135ade73e9021e04af93e08228f60ed630bc57f0132
7
+ data.tar.gz: 196e4761b8137046de0ebd00467f285a5e6985517f2537a41415c93686f49530b8ccdbbdff614b5246d1dc56871b2d8ef6787b7e98de0c795e9616b956671127
data/README.md CHANGED
@@ -35,6 +35,7 @@ model
35
35
  ```ruby
36
36
  class Invitation < ActiveRecord::Base
37
37
  include Booletania
38
+ booletania_columns :accepted
38
39
  end
39
40
  ```
40
41
 
@@ -1,9 +1,9 @@
1
1
  module Booletania
2
2
  class Attribute
3
3
  class << self
4
- def define_methods!(klass, boolean_columns)
5
- boolean_columns.each do |boolean_column|
6
- method_obj = Booletania::Method.new(klass, boolean_column)
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
 
@@ -1,18 +1,18 @@
1
1
  module Booletania
2
2
  class Method
3
- attr_reader :klass, :boolean_column
3
+ attr_reader :klass, :boolean_column_name
4
4
 
5
- def initialize(klass, boolean_column)
5
+ def initialize(klass, boolean_column_name)
6
6
  @klass = klass
7
- @boolean_column = boolean_column
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 #{boolean_column.name}_text
15
- keys = #{boolean_column.name}? ? #{i18n_true_keys} : #{i18n_false_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 #{boolean_column.name}_options
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}.#{boolean_column.name}"
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}/#{boolean_column.name}"
66
+ :"activerecord.attributes.#{klass.name.underscore}/#{boolean_column_name}"
67
67
  end
68
68
  end
69
69
  end
@@ -1,3 +1,3 @@
1
1
  module Booletania
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/booletania.rb CHANGED
@@ -3,12 +3,16 @@ require "booletania/method"
3
3
  require "booletania/attribute"
4
4
 
5
5
  module Booletania
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- raise ArgumentError, "booletania only support ActiveRecord" unless ancestors.include? ActiveRecord::Base
10
- raise ArgumentError, "not found .columns method" unless respond_to? :columns
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
- Booletania::Attribute.define_methods!(self, columns.select{ |column| column.type == :boolean })
13
+ module ClassMethods
14
+ def booletania_columns(*columns)
15
+ Booletania::Attribute.define_methods!(self, columns)
16
+ end
13
17
  end
14
18
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  class Invitation < ActiveRecord::Base
4
4
  include Booletania
5
+ booletania_columns :accepted1, :accepted2, :accepted3, :accepted4
5
6
  end
6
7
 
7
8
  # not AR
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: 0.1.0
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-02-07 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord