enumbler 0.6.8 → 0.6.14

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
2
  SHA256:
3
- metadata.gz: 4ddaace87d45b05778db532d5d0d4d4b28a475a02ec7079f1dff8820edc05d24
4
- data.tar.gz: b24dd09f614e8e32bed14b17bd9a36a8db1907dd4cb6e7614f73897394de3ef6
3
+ metadata.gz: 66bbc4c564df073b9bc20f03c8910c4f20c41d807c263f07184ad858e9cb96eb
4
+ data.tar.gz: cedfcee8d80c6a453c8ddea9954c40405da2558d3be9e603fc0d5f6d8bf42986
5
5
  SHA512:
6
- metadata.gz: 98349a3658d0cef8674e4a63a577a4b9e71279a4051d292f9b817fd5d8e1a2c0c837fdbb3b3cc01cac6de6219558a567eaafc9b0567d35e09bfe7b5d1689ce2c
7
- data.tar.gz: 2a52456e1524c22fd224e18421fea42bff5f45fd35f016dddce701df59c7ae5edb3738555faa26ce2fee4afaae7d94043997a6e25d15414cba5bd7872f97a237
6
+ metadata.gz: e3ed4b05cd073b3586922f4836e7529ae8f9360c8bf5231d4ba436abe176c788577db93215af9ef9d675da48ae15ffe796db81cdefb3c55f1d8f8ae741f4390d
7
+ data.tar.gz: dba88529dafd834bf7c5dbd522b52fadb6ab18b975493e091ba349c1a10dee5652dac21ad5b70e50f231e6620bca909768a0fa3219eb105a59ebafc75389d30d
@@ -3,6 +3,8 @@ name: CI Matrix Testing
3
3
  on:
4
4
  push:
5
5
  branches: [ master ]
6
+ tags:
7
+ - "*"
6
8
  pull_request:
7
9
  branches: [ master ]
8
10
 
@@ -51,6 +53,7 @@ jobs:
51
53
  ruby-version: 2.7.x
52
54
 
53
55
  - name: Publish to RubyGems
56
+ if: contains(github.ref, 'refs/tags/')
54
57
  run: |
55
58
  mkdir -p $HOME/.gem
56
59
  touch $HOME/.gem/credentials
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumbler (0.6.8)
4
+ enumbler (0.6.14)
5
5
  activerecord (>= 5.2.3, < 6.1)
6
6
  activesupport (>= 5.2.3, < 6.1)
7
7
 
@@ -57,7 +57,7 @@ module Enumbler
57
57
  # example: `where_by` will make it `House.where_by_color(:black)`
58
58
  # @param **options [Hash] additional options passed to `belongs_to`
59
59
  def enumbled_to(name, scope = nil, prefix: false, scope_prefix: nil, **options)
60
- class_name = name.to_s.classify
60
+ class_name = options.fetch(:class_name, name.to_s.classify)
61
61
  enumbled_model = class_name.constantize
62
62
 
63
63
  unless enumbled_model.respond_to?(:enumbles)
@@ -68,7 +68,7 @@ module Enumbler
68
68
  belongs_to(name, scope, **options)
69
69
 
70
70
  define_helper_attributes(name)
71
- define_dynamic_methods_for_enumbled_to_models(enumbled_model, prefix: prefix, scope_prefix: scope_prefix)
71
+ define_dynamic_methods_for_enumbled_to_models(name, enumbled_model, prefix: prefix, scope_prefix: scope_prefix)
72
72
  rescue NameError
73
73
  raise Error, "The model #{class_name} cannot be found. Uninitialized constant."
74
74
  end
@@ -80,11 +80,10 @@ module Enumbler
80
80
  # @todo - we should check for naming conflicts!
81
81
  # dangerous_attribute_method?(method_name)
82
82
  # method_defined_within?(method_name, self, Module)
83
- def define_dynamic_methods_for_enumbled_to_models(enumbled_model, prefix: false, scope_prefix: nil)
84
- model_name = enumbled_model.to_s.underscore
85
- column_name = "#{model_name}_id"
83
+ def define_dynamic_methods_for_enumbled_to_models(name, enumbled_model, prefix: false, scope_prefix: nil)
84
+ column_name = "#{name}_id"
86
85
 
87
- cmethod = scope_prefix.blank? ? model_name : "#{scope_prefix}_#{model_name}"
86
+ cmethod = scope_prefix.blank? ? name : "#{scope_prefix}_#{name}"
88
87
  define_singleton_method(cmethod) do |*args|
89
88
  where(column_name => enumbled_model.ids_from_enumbler(args))
90
89
  end
@@ -94,8 +93,8 @@ module Enumbler
94
93
  end
95
94
 
96
95
  enumbled_model.enumbles.each do |enumble|
97
- method_name = prefix ? "#{model_name}_#{enumble.enum}?" : "#{enumble.enum}?"
98
- not_method_name = prefix ? "#{model_name}_not_#{enumble.enum}?" : "not_#{enumble.enum}?"
96
+ method_name = prefix ? "#{name}_#{enumble.enum}?" : "#{enumble.enum}?"
97
+ not_method_name = prefix ? "#{name}_not_#{enumble.enum}?" : "not_#{enumble.enum}?"
99
98
  define_method(method_name) { self[column_name] == enumble.id }
100
99
  define_method(not_method_name) { self[column_name] != enumble.id }
101
100
  end
@@ -17,13 +17,29 @@ module Enumbler
17
17
  @enumble
18
18
  end
19
19
 
20
+ # The enumble graphql_enum if it exists.
21
+ # @return [Symbol]
22
+ def to_graphql_enum
23
+ to_enumble_attribute(:graphql_enum) || super
24
+ end
25
+
20
26
  # The enumble label if it exists.
21
27
  # @return [String]
22
28
  def to_s
23
- enumble = self.class.find_enumble(id)
24
- return enumble.label if enumble.present?
29
+ to_enumble_attribute(:label) || super
30
+ end
25
31
 
26
- super
32
+ # The enumble symbol if it exists.
33
+ # @return [Symbol]
34
+ def to_sym
35
+ to_enumble_attribute(:enum) || super
36
+ end
37
+
38
+ private
39
+
40
+ def to_enumble_attribute(attribute)
41
+ enumble = self.class.find_enumble(id)
42
+ return enumble.send(attribute) if enumble.present?
27
43
  end
28
44
 
29
45
  # These ClassMethods can be included in any model that you wish to
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enumbler
4
- VERSION = '0.6.8'
4
+ VERSION = '0.6.14'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Timm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord