enumbler 0.6.2 → 0.6.3

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: 95d8b5d35cb1f59fe24b30b944e5a834ce43c26f17e951b7cc164106cd0b9c7e
4
- data.tar.gz: cb4f46ece4d9bd70f7c6f1e06bb515c1fbbc8601bdb6785458a838f242a5f5c6
3
+ metadata.gz: 29989e16025afc87b0db8fd70347b21978c683ab44c6ffa2d1f44a22c20fb166
4
+ data.tar.gz: 807a16dd6e6ff6e8c95b3f5337acf2f1ea456d07378dc702b8f2672c0b862276
5
5
  SHA512:
6
- metadata.gz: a1c7cd257da559c741b9932dd160e757a83e080c26f7d0fc88df0e2996b155222ad5c517c675a7ad1694a09433fca864c34328f63f1c5c41b99ebc7df27eec03
7
- data.tar.gz: 361d082e5872d0fc5c8a03a1d5002ba622ef963ac9ce0add18a1238ea15241cc7e509d8e9f4bbac8644eb11fc741ad9cf6fd649d3103028b336f91928763333d
6
+ metadata.gz: 2c8dbf495025d467ee30172289097169d84d23776320a1624d5e3920f2f66e738f606a15e61e2bbce696051c6d87ec99c811c45b3d9cdcb631f7e3bd1b961409
7
+ data.tar.gz: 3a6d12fe63ff37e1274b5ec3ec31023aa08f520f455b44695746a5555a20bc063283fbd6afaf2f9831d740588bcf090426647f052c1bc87e98d829a071a9fc7d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumbler (0.6.2)
4
+ enumbler (0.6.3)
5
5
  activerecord (>= 5.2.3, < 6.1)
6
6
  activesupport (>= 5.2.3, < 6.1)
7
7
 
data/README.md CHANGED
@@ -86,10 +86,14 @@ Color.ids_from_enumbler!(:black, 'does-no-exist') # => raises Enumbler::Error
86
86
  Color.id_from_enumbler!(:does_not_exist) # => raises Enumbler::Error
87
87
 
88
88
  # Get enumble object by id
89
-
90
89
  house = House.create!(color: Color.black)
91
- house.black?
92
- house.not_black?
90
+
91
+ # These are all db-free lookups
92
+ house.color_label # => 'black'
93
+ house.color_enum # => :black
94
+ house.color_graphql_enum # => 'BLACK'
95
+ house.black? # => true
96
+ house.not_black? # => false
93
97
 
94
98
  house2 = House.create!(color: Color.white)
95
99
  House.color(:black, :white) # => ActiveRecord::Relation<house, house2>
@@ -65,6 +65,7 @@ module Enumbler
65
65
 
66
66
  belongs_to(name, scope, **options)
67
67
 
68
+ define_helper_attributes(name)
68
69
  define_dynamic_methods_for_enumbled_to_models(enumbled_model, prefix: prefix, scope_prefix: scope_prefix)
69
70
  rescue NameError
70
71
  raise Error, "The model #{class_name} cannot be found. Uninitialized constant."
@@ -97,5 +98,16 @@ module Enumbler
97
98
  define_method(not_method_name) { self[column_name] != enumble.id }
98
99
  end
99
100
  end
101
+
102
+ # Add the attirbutes:
103
+ #
104
+ # house.color_label #=> 'black'
105
+ # house.color_enum #=> :black
106
+ # house.color_graphql_enum #=> 'BLACK'
107
+ def define_helper_attributes(name)
108
+ %i[label enum graphql_enum].each do |sym|
109
+ define_method("#{name}_#{sym}") { send(name).enumble.send(sym) }
110
+ end
111
+ end
100
112
  end
101
113
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enumbler
4
- VERSION = '0.6.2'
4
+ VERSION = '0.6.3'
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.2
4
+ version: 0.6.3
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-07-04 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord