swifter_enum 0.9.2 → 0.9.4

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: 4147b58f08c0633761d7721503972bf4478d7b6295a634186810ebe146416bf8
4
- data.tar.gz: 9fa17a88143342a5637866c8ac599a5bc9adb6e7ff3f28293aefac6957ef3767
3
+ metadata.gz: a0b96e6c66d225905968a0a5b44a921c1aa01c2d567a6ce215fa2021a88f64de
4
+ data.tar.gz: f5a824043a596b0587195bc415784f411005e1d5b989ac0afa5a14a0f9b69893
5
5
  SHA512:
6
- metadata.gz: c322303bcf61cd899f66b0e444de08a4d4826cc787d2ef5fa53bda9f81b15130d4da4b6d63455c1215f5ef14b3cb523ac6112b8d62d4f61da069336e3d69c5e0
7
- data.tar.gz: 7e53b29f10e6908f3f9bf3f282c98d6e40f9a5c6bd5103d1beee337870c2ac53430cc3c0d0818c021731178c19e236d261573aa65fe6ce9b0d1a1b9624563e8a
6
+ metadata.gz: 4b480834e9d30c76b3a59b113247a7ba41f51699af40be97d1183236dd33ec5fe49d231f1b4b29b2de15d8ce567ba98d3d6118a6811dd124994adc4ed7cb3440
7
+ data.tar.gz: a3b43c3c21afcbab79ce070b0156298835a8f61c369411eb14271ffd72db48aaadb8906ebeee7b80af0bbaa592248636724a14c91c187fbeaffeb6988d1c0941
data/CHANGELOG.md CHANGED
@@ -7,4 +7,16 @@
7
7
 
8
8
  ## [0.9.1] - 2024-03-10
9
9
 
10
- - Fix use of options to use current syntax. Use prefix: true, rather than _prefix: true
10
+ - Fix use of options to use current syntax. Use prefix: true, rather than _prefix: true
11
+
12
+ ## [0.9.2]
13
+
14
+ - Allow String keys
15
+
16
+ ## [0.9.3]
17
+
18
+ - Fix generator & freeze values
19
+
20
+ ## [0.9.4]
21
+
22
+ - Add 'all_cases'
@@ -6,15 +6,19 @@ module SwifterEnum
6
6
  def set_values(input)
7
7
  case input
8
8
  when Hash
9
- @values = input
9
+ @values = input.freeze
10
10
  when Array
11
11
  validate_array_elements!(input)
12
- @values = input.map { |item| [item.to_sym, item.to_s] }.to_h
12
+ @values = input.map { |item| [item.to_sym, item.to_s] }.to_h.freeze
13
13
  else
14
14
  raise ArgumentError, "Input must be a Hash or an Array of symbols or strings"
15
15
  end
16
16
  end
17
17
 
18
+ def all_cases
19
+ @values.keys.map { |key| new(key) }
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def validate_array_elements!(array)
@@ -24,7 +28,7 @@ module SwifterEnum
24
28
  end
25
29
  end
26
30
 
27
- attr_reader :value
31
+ attr_accessor :value
28
32
 
29
33
  def initialize(value)
30
34
  @value = value&.to_sym
@@ -39,11 +43,11 @@ module SwifterEnum
39
43
  end
40
44
 
41
45
  def t
42
- I18n.t("swifter_enum.#{self.class.name.demodulize.underscore}.#{@value}")
46
+ I18n.t("swifter_enum.#{self.class.name.demodulize.underscore}.#{value}")
43
47
  end
44
48
 
45
49
  def to_s
46
- @value
50
+ value.to_s
47
51
  end
48
52
 
49
53
  def self.all
@@ -10,7 +10,7 @@ class <%= class_name %>Enum < SwifterEnum::Base
10
10
  #if you're using an array of symbols (or strings), then your database column should be of string type
11
11
  # e.g. set_values [:active,:passive]
12
12
 
13
- set_values <<Your Values Here>>
13
+ set_values ##Your Values Here##
14
14
 
15
15
  # you can now define methods on the enum
16
16
  # this would allow you to access YourModel.<%= file_name %>.squared
@@ -1,5 +1,11 @@
1
1
  require "active_support/concern"
2
2
 
3
+ # Adds methods to Rails Models
4
+ # swifter_enum
5
+ # model.enum_attribute (getter/setter)
6
+ # model.enum_attribute_raw (getter/setter to underlying enum)
7
+ # model.enum_attribute_raws
8
+
3
9
  module SwifterEnum
4
10
  extend ActiveSupport::Concern
5
11
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwifterEnum
4
- VERSION = "0.9.2"
4
+ VERSION = "0.9.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swifter_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Jonson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-12 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord