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 +4 -4
- data/.github/workflows/ruby.yml +3 -0
- data/Gemfile.lock +1 -1
- data/lib/enumbler.rb +7 -8
- data/lib/enumbler/enabler.rb +19 -3
- data/lib/enumbler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66bbc4c564df073b9bc20f03c8910c4f20c41d807c263f07184ad858e9cb96eb
|
4
|
+
data.tar.gz: cedfcee8d80c6a453c8ddea9954c40405da2558d3be9e603fc0d5f6d8bf42986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3ed4b05cd073b3586922f4836e7529ae8f9360c8bf5231d4ba436abe176c788577db93215af9ef9d675da48ae15ffe796db81cdefb3c55f1d8f8ae741f4390d
|
7
|
+
data.tar.gz: dba88529dafd834bf7c5dbd522b52fadb6ab18b975493e091ba349c1a10dee5652dac21ad5b70e50f231e6620bca909768a0fa3219eb105a59ebafc75389d30d
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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
|
data/Gemfile.lock
CHANGED
data/lib/enumbler.rb
CHANGED
@@ -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
|
-
|
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? ?
|
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 ? "#{
|
98
|
-
not_method_name = prefix ? "#{
|
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
|
data/lib/enumbler/enabler.rb
CHANGED
@@ -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
|
-
|
24
|
-
|
29
|
+
to_enumble_attribute(:label) || super
|
30
|
+
end
|
25
31
|
|
26
|
-
|
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
|
data/lib/enumbler/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|