anchormodel 0.0.2 → 0.1.1
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/.ruby-version +1 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +206 -0
- data/README.md +98 -9
- data/Rakefile +23 -3
- data/anchormodel.gemspec +26 -10
- data/bin/rails +7 -0
- data/doc/Anchormodel/ActiveModelTypeValue.html +14 -10
- data/doc/Anchormodel/Attribute.html +75 -71
- data/doc/Anchormodel/ModelMixin.html +190 -21
- data/doc/Anchormodel/Version.html +4 -4
- data/doc/Anchormodel.html +151 -53
- data/doc/_index.html +2 -2
- data/doc/file.README.html +118 -47
- data/doc/index.html +118 -47
- data/doc/method_list.html +9 -1
- data/doc/top-level-namespace.html +2 -2
- data/lib/anchormodel/active_model_type_value.rb +4 -4
- data/lib/anchormodel/attribute.rb +4 -9
- data/lib/anchormodel/model_mixin.rb +53 -3
- data/lib/anchormodel/version.rb +2 -2
- data/lib/anchormodel.rb +7 -2
- data/logo.svg +98 -0
- data/test/active_record_model/user_test.rb +115 -0
- data/test/dummy/.gitignore +29 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/anchormodels/locale.rb +6 -0
- data/test/dummy/app/anchormodels/role.rb +14 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/application_record.rb +5 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/user.rb +6 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +33 -0
- data/test/dummy/config/application.rb +37 -0
- data/test/dummy/config/boot.rb +3 -0
- data/test/dummy/config/credentials.yml.enc +1 -0
- data/test/dummy/config/database.yml +8 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/test.rb +50 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/permissions_policy.rb +11 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +43 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/config.ru +6 -0
- data/test/dummy/db/migrate/20230107173151_create_users.rb +12 -0
- data/test/dummy/db/schema.rb +23 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/lib/tasks/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/tmp/.keep +0 -0
- data/test/dummy/tmp/pids/.keep +0 -0
- data/test/test_helper.rb +21 -0
- metadata +149 -13
- data/anchormodel-0.0.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c228e4a1d684b6404a0f1376566680fecb2b458b5e0d5f9df0b41ab11b3facba
|
4
|
+
data.tar.gz: db3a4648ac8d41ca4bed6d9d540777e4c9a42b9e52e3500df2d5826429ef5b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5a8c1d45cba54da1a1061f9c680111cbdfbe00daa33e95883540777f96bfa3f070cadfc07ffaff6898d65d8111004851e4054475e6d611e5a1d48804e635e48
|
7
|
+
data.tar.gz: bf2fcc0048940551e969112f4ad522743bddc8d4c1fd84c3a45d6fc0161e99dc006db06c0480ebbd19afef3cbaa403d6b9dcbaf4dec294b14271c4de6bdbf697
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# Unreleased
|
2
|
+
|
3
|
+
- Add boolean accessor directly to all anchormodels
|
4
|
+
- Add ActiveRecord::Enum style readers, writers and scopes to the model
|
5
|
+
- Attribute#anchor_class is now called `anchormodel_class`.
|
6
|
+
|
7
|
+
# 0.1.0 (18.01.2023)
|
8
|
+
|
9
|
+
- Remove `Anchormodels::` prefix and have anchormodels in the root namespace instead.
|
10
|
+
- Add basic testing
|
11
|
+
|
1
12
|
# 0.0.2 (30.12.2022)
|
2
13
|
|
3
14
|
- Fix a bug where `.all` loaded entries from all classes.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
anchormodel (0.1.1.edge)
|
5
|
+
rails (~> 7.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (7.0.4)
|
11
|
+
actionpack (= 7.0.4)
|
12
|
+
activesupport (= 7.0.4)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (7.0.4)
|
16
|
+
actionpack (= 7.0.4)
|
17
|
+
activejob (= 7.0.4)
|
18
|
+
activerecord (= 7.0.4)
|
19
|
+
activestorage (= 7.0.4)
|
20
|
+
activesupport (= 7.0.4)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
net-imap
|
23
|
+
net-pop
|
24
|
+
net-smtp
|
25
|
+
actionmailer (7.0.4)
|
26
|
+
actionpack (= 7.0.4)
|
27
|
+
actionview (= 7.0.4)
|
28
|
+
activejob (= 7.0.4)
|
29
|
+
activesupport (= 7.0.4)
|
30
|
+
mail (~> 2.5, >= 2.5.4)
|
31
|
+
net-imap
|
32
|
+
net-pop
|
33
|
+
net-smtp
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
actionpack (7.0.4)
|
36
|
+
actionview (= 7.0.4)
|
37
|
+
activesupport (= 7.0.4)
|
38
|
+
rack (~> 2.0, >= 2.2.0)
|
39
|
+
rack-test (>= 0.6.3)
|
40
|
+
rails-dom-testing (~> 2.0)
|
41
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
42
|
+
actiontext (7.0.4)
|
43
|
+
actionpack (= 7.0.4)
|
44
|
+
activerecord (= 7.0.4)
|
45
|
+
activestorage (= 7.0.4)
|
46
|
+
activesupport (= 7.0.4)
|
47
|
+
globalid (>= 0.6.0)
|
48
|
+
nokogiri (>= 1.8.5)
|
49
|
+
actionview (7.0.4)
|
50
|
+
activesupport (= 7.0.4)
|
51
|
+
builder (~> 3.1)
|
52
|
+
erubi (~> 1.4)
|
53
|
+
rails-dom-testing (~> 2.0)
|
54
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
55
|
+
activejob (7.0.4)
|
56
|
+
activesupport (= 7.0.4)
|
57
|
+
globalid (>= 0.3.6)
|
58
|
+
activemodel (7.0.4)
|
59
|
+
activesupport (= 7.0.4)
|
60
|
+
activerecord (7.0.4)
|
61
|
+
activemodel (= 7.0.4)
|
62
|
+
activesupport (= 7.0.4)
|
63
|
+
activestorage (7.0.4)
|
64
|
+
actionpack (= 7.0.4)
|
65
|
+
activejob (= 7.0.4)
|
66
|
+
activerecord (= 7.0.4)
|
67
|
+
activesupport (= 7.0.4)
|
68
|
+
marcel (~> 1.0)
|
69
|
+
mini_mime (>= 1.1.0)
|
70
|
+
activesupport (7.0.4)
|
71
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
72
|
+
i18n (>= 1.6, < 2)
|
73
|
+
minitest (>= 5.1)
|
74
|
+
tzinfo (~> 2.0)
|
75
|
+
ansi (1.5.0)
|
76
|
+
ast (2.4.2)
|
77
|
+
builder (3.2.4)
|
78
|
+
coderay (1.1.3)
|
79
|
+
concurrent-ruby (1.1.10)
|
80
|
+
crass (1.0.6)
|
81
|
+
date (3.3.3)
|
82
|
+
erubi (1.12.0)
|
83
|
+
globalid (1.0.1)
|
84
|
+
activesupport (>= 5.0)
|
85
|
+
i18n (1.12.0)
|
86
|
+
concurrent-ruby (~> 1.0)
|
87
|
+
json (2.6.3)
|
88
|
+
loofah (2.19.1)
|
89
|
+
crass (~> 1.0.2)
|
90
|
+
nokogiri (>= 1.5.9)
|
91
|
+
mail (2.8.0.1)
|
92
|
+
mini_mime (>= 0.1.1)
|
93
|
+
net-imap
|
94
|
+
net-pop
|
95
|
+
net-smtp
|
96
|
+
marcel (1.0.2)
|
97
|
+
method_source (1.0.0)
|
98
|
+
mini_mime (1.1.2)
|
99
|
+
minitest (5.17.0)
|
100
|
+
minitest-reporters (1.5.0)
|
101
|
+
ansi
|
102
|
+
builder
|
103
|
+
minitest (>= 5.0)
|
104
|
+
ruby-progressbar
|
105
|
+
net-imap (0.3.4)
|
106
|
+
date
|
107
|
+
net-protocol
|
108
|
+
net-pop (0.1.2)
|
109
|
+
net-protocol
|
110
|
+
net-protocol (0.2.1)
|
111
|
+
timeout
|
112
|
+
net-smtp (0.3.3)
|
113
|
+
net-protocol
|
114
|
+
nio4r (2.5.8)
|
115
|
+
nokogiri (1.14.0-x86_64-linux)
|
116
|
+
racc (~> 1.4)
|
117
|
+
parallel (1.22.1)
|
118
|
+
parser (3.2.0.0)
|
119
|
+
ast (~> 2.4.1)
|
120
|
+
pry (0.14.1)
|
121
|
+
coderay (~> 1.1)
|
122
|
+
method_source (~> 1.0)
|
123
|
+
racc (1.6.2)
|
124
|
+
rack (2.2.5)
|
125
|
+
rack-test (2.0.2)
|
126
|
+
rack (>= 1.3)
|
127
|
+
rails (7.0.4)
|
128
|
+
actioncable (= 7.0.4)
|
129
|
+
actionmailbox (= 7.0.4)
|
130
|
+
actionmailer (= 7.0.4)
|
131
|
+
actionpack (= 7.0.4)
|
132
|
+
actiontext (= 7.0.4)
|
133
|
+
actionview (= 7.0.4)
|
134
|
+
activejob (= 7.0.4)
|
135
|
+
activemodel (= 7.0.4)
|
136
|
+
activerecord (= 7.0.4)
|
137
|
+
activestorage (= 7.0.4)
|
138
|
+
activesupport (= 7.0.4)
|
139
|
+
bundler (>= 1.15.0)
|
140
|
+
railties (= 7.0.4)
|
141
|
+
rails-dom-testing (2.0.3)
|
142
|
+
activesupport (>= 4.2.0)
|
143
|
+
nokogiri (>= 1.6)
|
144
|
+
rails-html-sanitizer (1.5.0)
|
145
|
+
loofah (~> 2.19, >= 2.19.1)
|
146
|
+
railties (7.0.4)
|
147
|
+
actionpack (= 7.0.4)
|
148
|
+
activesupport (= 7.0.4)
|
149
|
+
method_source
|
150
|
+
rake (>= 12.2)
|
151
|
+
thor (~> 1.0)
|
152
|
+
zeitwerk (~> 2.5)
|
153
|
+
rainbow (3.1.1)
|
154
|
+
rake (13.0.6)
|
155
|
+
regexp_parser (2.6.1)
|
156
|
+
rexml (3.2.5)
|
157
|
+
rubocop (1.43.0)
|
158
|
+
json (~> 2.3)
|
159
|
+
parallel (~> 1.10)
|
160
|
+
parser (>= 3.2.0.0)
|
161
|
+
rainbow (>= 2.2.2, < 4.0)
|
162
|
+
regexp_parser (>= 1.8, < 3.0)
|
163
|
+
rexml (>= 3.2.5, < 4.0)
|
164
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
165
|
+
ruby-progressbar (~> 1.7)
|
166
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
167
|
+
rubocop-ast (1.24.1)
|
168
|
+
parser (>= 3.1.1.0)
|
169
|
+
rubocop-rails (2.17.4)
|
170
|
+
activesupport (>= 4.2.0)
|
171
|
+
rack (>= 1.1)
|
172
|
+
rubocop (>= 1.33.0, < 2.0)
|
173
|
+
ruby-progressbar (1.11.0)
|
174
|
+
sqlite3 (1.6.0-x86_64-linux)
|
175
|
+
thor (1.2.1)
|
176
|
+
timeout (0.3.1)
|
177
|
+
tzinfo (2.0.5)
|
178
|
+
concurrent-ruby (~> 1.0)
|
179
|
+
unicode-display_width (2.4.2)
|
180
|
+
webrick (1.7.0)
|
181
|
+
websocket-driver (0.7.5)
|
182
|
+
websocket-extensions (>= 0.1.0)
|
183
|
+
websocket-extensions (0.1.5)
|
184
|
+
yard (0.9.28)
|
185
|
+
webrick (~> 1.7.0)
|
186
|
+
yard-activesupport-concern (0.0.1)
|
187
|
+
yard (>= 0.8)
|
188
|
+
zeitwerk (2.6.6)
|
189
|
+
|
190
|
+
PLATFORMS
|
191
|
+
x86_64-linux
|
192
|
+
|
193
|
+
DEPENDENCIES
|
194
|
+
anchormodel!
|
195
|
+
minitest (~> 5.17.0)
|
196
|
+
minitest-reporters (~> 1.5.0)
|
197
|
+
pry (~> 0.14.1)
|
198
|
+
rake (~> 13.0.6)
|
199
|
+
rubocop (~> 1.43.0)
|
200
|
+
rubocop-rails (~> 2.17.4)
|
201
|
+
sqlite3 (~> 1.6.0)
|
202
|
+
yard (~> 0.9.28)
|
203
|
+
yard-activesupport-concern (~> 0.0.1)
|
204
|
+
|
205
|
+
BUNDLED WITH
|
206
|
+
2.3.26
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
<img src="logo.svg" height=250 alt="Anchormodel logo"/>
|
2
|
+
|
1
3
|
# Introducing Anchormodel
|
2
4
|
|
3
5
|
This gem provides a simple but powerful alternative to [Rails
|
@@ -42,18 +44,27 @@ meaningful, making you immediately understand what they stand for.
|
|
42
44
|
This is why Anchormodel is strictly relying on String keys corresponding to the
|
43
45
|
entries of an Anchormodel.
|
44
46
|
|
45
|
-
|
47
|
+
|
48
|
+
# Installation
|
49
|
+
|
50
|
+
1. Add gem to Gemfile: `gem 'anchormodel'`
|
51
|
+
2. In `application_record.rb`, add in the class body: `include Anchormodel::ModelMixin`
|
52
|
+
|
53
|
+
# Basic example
|
46
54
|
|
47
55
|
`app/anchormodels/role.rb`:
|
48
56
|
|
49
57
|
```ruby
|
50
|
-
class
|
58
|
+
class Role < Anchormodel
|
59
|
+
# Make <, > etc. based on <=> operator whic hwe will define below
|
60
|
+
include Comparable
|
61
|
+
|
51
62
|
# Expose the attribute privilege_level
|
52
63
|
attr_reader :privilege_level
|
53
64
|
|
54
|
-
#
|
65
|
+
# Define <=> to make user roles comparable based on the privilege level
|
55
66
|
def <=>(other)
|
56
|
-
|
67
|
+
@privilege_level <=> other.privilege_level
|
57
68
|
end
|
58
69
|
|
59
70
|
# Declare all available roles
|
@@ -68,7 +79,11 @@ end
|
|
68
79
|
```ruby
|
69
80
|
# The DB table `users` must have a String column `users.role`
|
70
81
|
class User < ApplicationRecord
|
82
|
+
# If `users.role` has an `NOT NULL` constraint, use:
|
71
83
|
belongs_to_anchormodel :role
|
84
|
+
|
85
|
+
# If `users.role` can be `NULL`, use the following instead:
|
86
|
+
belongs_to_anchormodel :role, optional: true
|
72
87
|
end
|
73
88
|
```
|
74
89
|
|
@@ -76,10 +91,10 @@ You may now use the following methods:
|
|
76
91
|
|
77
92
|
```ruby
|
78
93
|
# Retrieve all user roles:
|
79
|
-
|
94
|
+
Role.all
|
80
95
|
|
81
96
|
# Retrieve a specific role from the String and find its privilege level
|
82
|
-
|
97
|
+
Role.find(:guest).privilege_level
|
83
98
|
|
84
99
|
# Implement a Rails helper that makes sure users can only edit other users that have a lower privilege level than themselves
|
85
100
|
def user_can_edit?(this_user, other_user)
|
@@ -88,9 +103,83 @@ end
|
|
88
103
|
|
89
104
|
# Pretty print a user's role, e.g. using the Rails FastGettext gem:
|
90
105
|
puts("User #{@user.name} has role #{@user.role.label}")
|
106
|
+
|
107
|
+
# Check whether @user has role admin
|
108
|
+
@user.role.admin? # true if and only if the role is admin (false otherwise)
|
91
109
|
```
|
92
110
|
|
93
|
-
#
|
111
|
+
# Rails Enum style model methods
|
94
112
|
|
95
|
-
|
96
|
-
|
113
|
+
By default, Anchormodel adds three kinds of methods for each key to the model:
|
114
|
+
|
115
|
+
- a reader (getter)
|
116
|
+
- a writer (setter)
|
117
|
+
- a Rails scope
|
118
|
+
|
119
|
+
For instance:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
class User < ApplicationRecord
|
123
|
+
belongs_to_anchormodel :role # where Role has keys :guest, :manager and :admin
|
124
|
+
belongs_to_anchormodel :shape # where Shape has keys :circle and :rectangle
|
125
|
+
end
|
126
|
+
|
127
|
+
# User now implements the following methods, given that @user is retrieved as follows:
|
128
|
+
@user = User.first # for example
|
129
|
+
|
130
|
+
# Readers
|
131
|
+
@user.guest? # same as @user.role.guest?
|
132
|
+
@user.manager?
|
133
|
+
@user.admin?
|
134
|
+
@user.rectangle? # same as @user.shape.rectangle?
|
135
|
+
@user.circle?
|
136
|
+
# Writers
|
137
|
+
@user.guest! # same as @user.role = Role.find(:guest)
|
138
|
+
@user.manager!
|
139
|
+
@user.admin!
|
140
|
+
@user.rectangle! # same as @user.shape = Shape.find(:rectangle)
|
141
|
+
@user.circle!
|
142
|
+
# Scopes
|
143
|
+
User.guest # same as User.where(role: 'guest')
|
144
|
+
User.manager
|
145
|
+
User.admin
|
146
|
+
User.rectangle # same as User.where(shape: 'rectangle')
|
147
|
+
User.circle
|
148
|
+
```
|
149
|
+
|
150
|
+
This behavior is similar as the one from Rails Enums. If you want to disable it, use:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
class User < ApplicationRecord
|
154
|
+
belongs_to_anchormodel :role, model_readers: false, model_writers: false, model_scopes: false
|
155
|
+
# or, equivalent, to disable all at once:
|
156
|
+
belongs_to_anchormodel :role, model_methods: false
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
# Calling a column differently than the Anchormodel
|
161
|
+
|
162
|
+
If your column name (and the model's attribute) is called differently than the Anchormodel, you may give the Anchormodel's class as the second argument. For example:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
# app/anchormodels/color.rb
|
166
|
+
class Color < Anchormodel
|
167
|
+
new :green
|
168
|
+
new :red
|
169
|
+
end
|
170
|
+
|
171
|
+
# app/models/user.rb
|
172
|
+
class User < ApplicationRecord
|
173
|
+
belongs_to_anchormodel :favorite_color, Color
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
## Having multiple attributes to the same Anchormodel
|
178
|
+
|
179
|
+
If you want to have multiple attributes in the same model pointing to the same Anchormodel, you need to disable `model_methods` for at least one of them (otherwise the model methods will clash in your model class):
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
# app/models/user.rb
|
183
|
+
belongs_to_anchormodel :role
|
184
|
+
belongs_to_anchormodel :secondary_role, Role, model_methods: false
|
185
|
+
```
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require_relative 'lib/anchormodel/version'
|
3
3
|
|
4
|
+
# Create "gemspec" task
|
4
5
|
task :gemspec do
|
5
6
|
specification = Gem::Specification.new do |s|
|
6
7
|
s.name = 'anchormodel'
|
@@ -11,12 +12,27 @@ task :gemspec do
|
|
11
12
|
s.executables = []
|
12
13
|
s.require_paths = ['lib']
|
13
14
|
s.required_ruby_version = '>= 3.0.0'
|
15
|
+
s.license = 'LGPL-3.0-or-later'
|
16
|
+
s.homepage = 'https://github.com/kalsan/anchormodel'
|
14
17
|
|
15
18
|
# Dependencies
|
16
|
-
s.add_runtime_dependency 'rails', '
|
19
|
+
s.add_runtime_dependency 'rails', '~> 7.0'
|
17
20
|
|
18
|
-
s.add_development_dependency '
|
19
|
-
s.add_development_dependency '
|
21
|
+
s.add_development_dependency 'rake', '~> 13.0.6'
|
22
|
+
s.add_development_dependency 'pry', '~> 0.14.1'
|
23
|
+
|
24
|
+
# Linter
|
25
|
+
s.add_development_dependency 'rubocop', '~> 1.43.0'
|
26
|
+
s.add_development_dependency 'rubocop-rails', '~> 2.17.4'
|
27
|
+
|
28
|
+
# Doc
|
29
|
+
s.add_development_dependency 'yard', '~> 0.9.28'
|
30
|
+
s.add_development_dependency 'yard-activesupport-concern', '~> 0.0.1'
|
31
|
+
|
32
|
+
# Test
|
33
|
+
s.add_development_dependency 'minitest', '~> 5.17.0'
|
34
|
+
s.add_development_dependency 'minitest-reporters', '~> 1.5.0'
|
35
|
+
s.add_development_dependency 'sqlite3', '~> 1.6.0'
|
20
36
|
end
|
21
37
|
|
22
38
|
File.open('anchormodel.gemspec', 'w') do |f|
|
@@ -25,3 +41,7 @@ task :gemspec do
|
|
25
41
|
f.write(specification.to_ruby.strip)
|
26
42
|
end
|
27
43
|
end
|
44
|
+
|
45
|
+
# Create "test" task
|
46
|
+
require 'minitest/test_task'
|
47
|
+
Minitest::TestTask.create
|
data/anchormodel.gemspec
CHANGED
@@ -2,17 +2,19 @@
|
|
2
2
|
# This file is auto-generated via: 'rake gemspec'.
|
3
3
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: anchormodel 0.
|
5
|
+
# stub: anchormodel 0.1.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "anchormodel".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.1.1"
|
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 = "
|
15
|
-
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "anchormodel
|
14
|
+
s.date = "2023-01-24"
|
15
|
+
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "anchormodel.gemspec".freeze, "bin/rails".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, "logo.svg".freeze, "test/active_record_model/user_test.rb".freeze, "test/dummy/.gitignore".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/anchormodels/locale.rb".freeze, "test/dummy/app/anchormodels/role.rb".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/credentials.yml.enc".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/content_security_policy.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/permissions_policy.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/db/migrate/20230107173151_create_users.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/db/seeds.rb".freeze, "test/dummy/lib/tasks/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/tmp/.keep".freeze, "test/dummy/tmp/pids/.keep".freeze, "test/test_helper.rb".freeze]
|
16
|
+
s.homepage = "https://github.com/kalsan/anchormodel".freeze
|
17
|
+
s.licenses = ["LGPL-3.0-or-later".freeze]
|
16
18
|
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
|
17
19
|
s.rubygems_version = "3.3.26".freeze
|
18
20
|
s.summary = "Bringing object-oriented programming to Rails enums".freeze
|
@@ -22,12 +24,26 @@ Gem::Specification.new do |s|
|
|
22
24
|
end
|
23
25
|
|
24
26
|
if s.respond_to? :add_runtime_dependency then
|
25
|
-
s.add_runtime_dependency(%q<rails>.freeze, ["
|
26
|
-
s.add_development_dependency(%q<
|
27
|
-
s.add_development_dependency(%q<
|
27
|
+
s.add_runtime_dependency(%q<rails>.freeze, ["~> 7.0"])
|
28
|
+
s.add_development_dependency(%q<rake>.freeze, ["~> 13.0.6"])
|
29
|
+
s.add_development_dependency(%q<pry>.freeze, ["~> 0.14.1"])
|
30
|
+
s.add_development_dependency(%q<rubocop>.freeze, ["~> 1.43.0"])
|
31
|
+
s.add_development_dependency(%q<rubocop-rails>.freeze, ["~> 2.17.4"])
|
32
|
+
s.add_development_dependency(%q<yard>.freeze, ["~> 0.9.28"])
|
33
|
+
s.add_development_dependency(%q<yard-activesupport-concern>.freeze, ["~> 0.0.1"])
|
34
|
+
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.17.0"])
|
35
|
+
s.add_development_dependency(%q<minitest-reporters>.freeze, ["~> 1.5.0"])
|
36
|
+
s.add_development_dependency(%q<sqlite3>.freeze, ["~> 1.6.0"])
|
28
37
|
else
|
29
|
-
s.add_dependency(%q<rails>.freeze, ["
|
30
|
-
s.add_dependency(%q<
|
31
|
-
s.add_dependency(%q<
|
38
|
+
s.add_dependency(%q<rails>.freeze, ["~> 7.0"])
|
39
|
+
s.add_dependency(%q<rake>.freeze, ["~> 13.0.6"])
|
40
|
+
s.add_dependency(%q<pry>.freeze, ["~> 0.14.1"])
|
41
|
+
s.add_dependency(%q<rubocop>.freeze, ["~> 1.43.0"])
|
42
|
+
s.add_dependency(%q<rubocop-rails>.freeze, ["~> 2.17.4"])
|
43
|
+
s.add_dependency(%q<yard>.freeze, ["~> 0.9.28"])
|
44
|
+
s.add_dependency(%q<yard-activesupport-concern>.freeze, ["~> 0.0.1"])
|
45
|
+
s.add_dependency(%q<minitest>.freeze, ["~> 5.17.0"])
|
46
|
+
s.add_dependency(%q<minitest-reporters>.freeze, ["~> 1.5.0"])
|
47
|
+
s.add_dependency(%q<sqlite3>.freeze, ["~> 1.6.0"])
|
32
48
|
end
|
33
49
|
end
|
data/bin/rails
ADDED
@@ -217,7 +217,8 @@
|
|
217
217
|
|
218
218
|
|
219
219
|
|
220
|
-
<span class="summary_desc"><div class='inline'
|
220
|
+
<span class="summary_desc"><div class='inline'>
|
221
|
+
<p>A new instance of ActiveModelTypeValue.</p>
|
221
222
|
</div></span>
|
222
223
|
|
223
224
|
</li>
|
@@ -240,7 +241,8 @@
|
|
240
241
|
|
241
242
|
|
242
243
|
|
243
|
-
<span class="summary_desc"><div class='inline'
|
244
|
+
<span class="summary_desc"><div class='inline'>
|
245
|
+
<p>Implementing this instead of cast to force key validation in any case.</p>
|
244
246
|
</div></span>
|
245
247
|
|
246
248
|
</li>
|
@@ -264,7 +266,8 @@
|
|
264
266
|
|
265
267
|
</h3><div class="docstring">
|
266
268
|
<div class="discussion">
|
267
|
-
|
269
|
+
|
270
|
+
<p>Returns a new instance of ActiveModelTypeValue.</p>
|
268
271
|
|
269
272
|
|
270
273
|
</div>
|
@@ -426,8 +429,8 @@
|
|
426
429
|
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line 29</span>
|
427
430
|
|
428
431
|
<span class='kw'>def</span> <span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
429
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
430
|
-
<span class='kw'>return</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
432
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='rparen'>)</span>
|
433
|
+
<span class='kw'>return</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
431
434
|
<span class='kw'>end</span></pre>
|
432
435
|
</td>
|
433
436
|
</tr>
|
@@ -445,7 +448,8 @@
|
|
445
448
|
|
446
449
|
</h3><div class="docstring">
|
447
450
|
<div class="discussion">
|
448
|
-
|
451
|
+
|
452
|
+
<p>Implementing this instead of cast to force key validation in any case</p>
|
449
453
|
|
450
454
|
|
451
455
|
</div>
|
@@ -481,11 +485,11 @@
|
|
481
485
|
<span class='kw'>def</span> <span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
482
486
|
<span class='kw'>return</span> <span class='kw'>case</span> <span class='id identifier rubyid_value'>value</span>
|
483
487
|
<span class='kw'>when</span> <span class='const'>Symbol</span><span class='comma'>,</span> <span class='const'>String</span>
|
484
|
-
<span class='kw'>unless</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
488
|
+
<span class='kw'>unless</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_valid_keys'>valid_keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rparen'>)</span>
|
485
489
|
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Attempt to set </span><span class='embexpr_beg'>#{</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> to unsupported key </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
486
490
|
<span class='kw'>end</span>
|
487
491
|
<span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
488
|
-
<span class='kw'>when</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
492
|
+
<span class='kw'>when</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
|
489
493
|
<span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
490
494
|
<span class='kw'>when</span> <span class='kw'>nil</span>
|
491
495
|
<span class='kw'>nil</span>
|
@@ -503,9 +507,9 @@
|
|
503
507
|
</div>
|
504
508
|
|
505
509
|
<div id="footer">
|
506
|
-
Generated on
|
510
|
+
Generated on Tue Jan 24 20:27:59 2023 by
|
507
511
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
508
|
-
0.9.28 (ruby-3.
|
512
|
+
0.9.28 (ruby-3.1.3).
|
509
513
|
</div>
|
510
514
|
|
511
515
|
</div>
|