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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbe7dc049f0299d1cb5354f8ff08982077fae71faeaa9323754b3dbd895c0800
4
- data.tar.gz: 2fcda84259a43a8137d0dfc86f9932f82588795f96acc545850fa0ca30ebaa0c
3
+ metadata.gz: 4e8757c4fd30584304c8f35dcc9d56bbe76d910a5dd4aca8bcd1205b8a16a96a
4
+ data.tar.gz: 6167dbc661dd04a78f6b5078ae498a280917084d61a9e65eb545bd21a3741565
5
5
  SHA512:
6
- metadata.gz: 51336e2f715dc1ad52120575ea33d023df747b47accda40f063bb5cc165aee07f290312114b8564e8f5bb2e281eb811c24c58185fd26a3f792b761eb636db081
7
- data.tar.gz: d7640ccdd0a5991b7d41746b9e86dee2bf33d483f0dd27f7d4134fc30e1683e1668d7ce1dc1f2940a521dc74090472497dc535a7b2424d0f3123127e71c13976
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
- # public API
15
- define_method(column_name.to_s.pluralize) { identifiers }
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 [] * id
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
- id.filter_map { identified_as _1 }
36
+ where @identified_by => id
31
37
  else
32
- identified_as id or
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
@@ -1,3 +1,3 @@
1
1
  module Organizer
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.1'
3
3
  end
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.3
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-05 00:00:00.000000000 Z
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.3/CHANGELOG.md
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: