organizer-rails 0.1.3 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/organizer/identifiable.rb +13 -12
- data/lib/organizer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e8757c4fd30584304c8f35dcc9d56bbe76d910a5dd4aca8bcd1205b8a16a96a
|
4
|
+
data.tar.gz: 6167dbc661dd04a78f6b5078ae498a280917084d61a9e65eb545bd21a3741565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0649f46e0edcd3bae00d6fb56d0fce8b4153da136f6e143d2c7e034cef6e6a00b66684d6a5cd50fc8cda69983736f9c15cc04ce06a503b85c983614a30db389
|
7
|
+
data.tar.gz: 422586546c3c9334bf4ad0ed6decb2eb5b095c3625fed75ff78271880f45b0f23cab44c4e24ad8681aba6d80c3cfe316760b8d09b7a62a9645232387efe25949
|
@@ -3,16 +3,22 @@ require 'memery'
|
|
3
3
|
module Organizer
|
4
4
|
concern :Identifiable do
|
5
5
|
class << self
|
6
|
-
def by column_name
|
6
|
+
def by column_name, symbolized: false
|
7
7
|
dup.tap do
|
8
8
|
_1.module_eval do
|
9
9
|
included do
|
10
10
|
@identified_by = column_name
|
11
|
+
@symbolize_ids = symbolized
|
11
12
|
end
|
12
13
|
|
13
|
-
class_methods do
|
14
|
-
|
15
|
-
|
14
|
+
class_methods do # public API
|
15
|
+
define_method column_name.to_s.pluralize do
|
16
|
+
if @symbolize_ids
|
17
|
+
identifiers.map &:to_sym
|
18
|
+
else
|
19
|
+
identifiers
|
20
|
+
end.to_set
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -22,14 +28,14 @@ module Organizer
|
|
22
28
|
class_methods do
|
23
29
|
include Memery
|
24
30
|
|
25
|
-
def [] *
|
31
|
+
def [] *id
|
26
32
|
return id.map { self[_1] } if id.many?
|
27
33
|
|
28
34
|
case id = id.first
|
29
35
|
when Enumerable
|
30
|
-
|
36
|
+
where @identified_by => id
|
31
37
|
else
|
32
|
-
|
38
|
+
find_by @identified_by => id or
|
33
39
|
raise ArgumentError, "Couldn't find #{self} `#{id}`"
|
34
40
|
end
|
35
41
|
end
|
@@ -38,11 +44,6 @@ module Organizer
|
|
38
44
|
|
39
45
|
memoize def identifiers
|
40
46
|
all.pluck(@identified_by)
|
41
|
-
.map &:to_sym
|
42
|
-
end
|
43
|
-
|
44
|
-
memoize def identified_as identifier
|
45
|
-
find_by @identified_by => identifier
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
data/lib/organizer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: organizer-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Senko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,7 +72,7 @@ licenses:
|
|
72
72
|
metadata:
|
73
73
|
homepage_uri: https://github.com/Alexander-Senko/organizer
|
74
74
|
source_code_uri: https://github.com/Alexander-Senko/organizer
|
75
|
-
changelog_uri: https://github.com/Alexander-Senko/organizer/blob/v0.1
|
75
|
+
changelog_uri: https://github.com/Alexander-Senko/organizer/blob/v0.2.1/CHANGELOG.md
|
76
76
|
post_install_message:
|
77
77
|
rdoc_options: []
|
78
78
|
require_paths:
|