anchormodel 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/anchormodel-0.0.1.gem +0 -0
- data/anchormodel.gemspec +5 -5
- data/lib/anchormodel/version.rb +1 -1
- data/lib/anchormodel.rb +13 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2689ea9bc922423d95855c1ad4e37399ae31c67dfe7babe6a900b3c2c2cf5d4b
|
4
|
+
data.tar.gz: c2276b07545a72726e233f8d11acc8ec398f9ed4e6ab85c44ddd9d4e446154aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49a9821044b8e5a4d05c3c095be0b39f7a1edc56ba3ad54f1dd74adccab2859ddf356fec18662d338735b132ab332f52b1903b9d82487f053401cd94e7ed734f
|
7
|
+
data.tar.gz: 6862cb3d1d31db695c8b6afec195cdd0a3a0fa02530767418b59f6a63a19a45891828cb57bb48d8b8609ee2da2c92503a1edf03a12693869ee5ae54383d1cb91
|
data/CHANGELOG.md
ADDED
Binary file
|
data/anchormodel.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
# This file is auto-generated via: 'rake gemspec'.
|
3
3
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: anchormodel 0.0.
|
5
|
+
# stub: anchormodel 0.0.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "anchormodel".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Sandro Kalbermatter".freeze]
|
14
|
-
s.date = "2022-12-
|
15
|
-
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "anchormodel.gemspec".freeze, "doc/Anchormodel.html".freeze, "doc/Anchormodel/ActiveModelTypeValue.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "lib/anchormodel.rb".freeze, "lib/anchormodel/active_model_type_value.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/version.rb".freeze]
|
14
|
+
s.date = "2022-12-30"
|
15
|
+
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "anchormodel-0.0.1.gem".freeze, "anchormodel.gemspec".freeze, "doc/Anchormodel.html".freeze, "doc/Anchormodel/ActiveModelTypeValue.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "lib/anchormodel.rb".freeze, "lib/anchormodel/active_model_type_value.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/version.rb".freeze]
|
16
16
|
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
|
17
|
-
s.rubygems_version = "3.
|
17
|
+
s.rubygems_version = "3.3.26".freeze
|
18
18
|
s.summary = "Bringing object-oriented programming to Rails enums".freeze
|
19
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
data/lib/anchormodel/version.rb
CHANGED
data/lib/anchormodel.rb
CHANGED
@@ -5,10 +5,21 @@ class Anchormodel
|
|
5
5
|
attr_reader :key
|
6
6
|
attr_reader :index
|
7
7
|
|
8
|
+
class_attribute :setup_completed, default: false
|
8
9
|
class_attribute :entries_list, default: [] # For ordering
|
9
10
|
class_attribute :entries_hash, default: {} # For quick access
|
10
11
|
class_attribute :valid_keys, default: Set.new
|
11
12
|
|
13
|
+
# When a descendant of Anchormodel is first used, it must overwrite the class_attributes
|
14
|
+
# to prevent cross-class pollution.
|
15
|
+
def self.setup!
|
16
|
+
fail("`setup!` was called twice for Anchormodel subclass #{to_s}.") if setup_completed
|
17
|
+
self.entries_list = entries_list.dup
|
18
|
+
self.entries_hash = entries_hash.dup
|
19
|
+
self.valid_keys = valid_keys.dup
|
20
|
+
self.setup_completed = true
|
21
|
+
end
|
22
|
+
|
12
23
|
# Returns all possible values this Anchormodel can take.
|
13
24
|
def self.all
|
14
25
|
entries_list
|
@@ -25,6 +36,8 @@ class Anchormodel
|
|
25
36
|
# @param key [String,Symbol] The key under which the entry should be stored.
|
26
37
|
# @param attributes All named arguments to Anchormodel are made available as instance attributes.
|
27
38
|
def initialize(key, **attributes)
|
39
|
+
self.class.setup! unless self.class.setup_completed
|
40
|
+
|
28
41
|
@key = key.to_sym
|
29
42
|
@index = entries_list.count
|
30
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anchormodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Kalbermatter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -61,9 +61,11 @@ files:
|
|
61
61
|
- ".gitignore"
|
62
62
|
- ".ruby-version"
|
63
63
|
- ".yardopts"
|
64
|
+
- CHANGELOG.md
|
64
65
|
- LICENSE
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
68
|
+
- anchormodel-0.0.1.gem
|
67
69
|
- anchormodel.gemspec
|
68
70
|
- doc/Anchormodel.html
|
69
71
|
- doc/Anchormodel/ActiveModelTypeValue.html
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
- !ruby/object:Gem::Version
|
108
110
|
version: '0'
|
109
111
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.3.26
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: Bringing object-oriented programming to Rails enums
|