organizer-rails 0.1.2 → 0.2.0

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: 11e69d2d9cbaf1a19330830f731e89a0bda262b646a9de7254e33ccdaad99033
4
- data.tar.gz: 2ff6b86f0ba4f631917975a6836c8514dafb67231ffc99d99480673d17fbaf3a
3
+ metadata.gz: 145be80c0dc4c6b9c012b474c6958d8891aa81143c39cdff4749d5713de2ad02
4
+ data.tar.gz: 3b83640f157bc0980e2d8867a32a08e71e407adc332912b3ed49d0e72317dd34
5
5
  SHA512:
6
- metadata.gz: ee05963bc089ac9aa932cf2a5e507a97355fee6ebee75873dd86990044d79335d2a2600145d4e8907d9cff632ff6141854a9bca248011d34b661a71b79ecc99d
7
- data.tar.gz: 8616a59b07b85f3b82e45edcf7d5920289870e2b31337074138dfcc347909f1bf13b957e5ed99a71141f087638306535f13184d38257a971ce5132ca8b567e22
6
+ metadata.gz: 2e363e498d9d7ce66a643e90e9021371faeba2eccbeb3ee48d4df10906d641ccc0ffcde22f6287949893f1b9dc258c220e01818ab36a11ccc5f7b03aa6839227
7
+ data.tar.gz: 96c82bafd31b4132f8cf0ec2032064302889781a48232c9d60644d061ebffdbbc8090fe95f78cbfce7ffe551dab4755f3c7985549a862fe59eccfc8631608cc0
data/README.md CHANGED
@@ -21,7 +21,7 @@ MyModel[:my_name] # => #<MyModel1 id: 1, name: "my_name">
21
21
  Add this line to your application's Gemfile:
22
22
 
23
23
  ```ruby
24
- gem "organizer-rails"
24
+ gem "organizer-rails", require: "organizer"
25
25
  ```
26
26
 
27
27
  And then execute:
@@ -1,15 +1,24 @@
1
+ require 'memery'
2
+
1
3
  module Organizer
2
4
  concern :Identifiable do
3
5
  class << self
4
- def by column_name
6
+ def by column_name, symbolized: false
5
7
  dup.tap do
6
8
  _1.module_eval do
7
9
  included do
8
10
  @identified_by = column_name
11
+ @symbolize_ids = symbolized
9
12
  end
10
13
 
11
14
  class_methods do # public API
12
- define_method(column_name.to_s.pluralize) { identifiers }
15
+ define_method column_name.to_s.pluralize do
16
+ if @symbolize_ids
17
+ identifiers.map &:to_sym
18
+ else
19
+ identifiers
20
+ end
21
+ end
13
22
  end
14
23
  end
15
24
  end
@@ -17,29 +26,24 @@ module Organizer
17
26
  end
18
27
 
19
28
  class_methods do
29
+ include Memery
30
+
20
31
  def [] *id
21
32
  return id.map { self[_1] } if id.many?
22
33
 
23
34
  case id = id.first
24
35
  when Enumerable
25
- id.filter_map { identified_as _1 }
36
+ where @identified_by => id
26
37
  else
27
- identified_as id or
38
+ find_by @identified_by => id or
28
39
  raise ArgumentError, "Couldn't find #{self} `#{id}`"
29
40
  end
30
41
  end
31
42
 
32
43
  private
33
44
 
34
- def identifiers
35
- @identifiers ||= # cache
36
- all.pluck(@identified_by)
37
- .map &:to_sym
38
- end
39
-
40
- def identified_as identifier
41
- (@identified ||= {}.with_indifferent_access)[identifier] ||= # cache
42
- find_by @identified_by => identifier
45
+ memoize def identifiers
46
+ all.pluck(@identified_by)
43
47
  end
44
48
  end
45
49
  end
@@ -1,3 +1,3 @@
1
1
  module Organizer
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
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.2
4
+ version: 0.2.0
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-01-28 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: memery
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Use lists, tags, flags, etc. to organize your application records.
28
42
  email:
29
43
  - Alexander.Senko@gmail.com
@@ -58,7 +72,7 @@ licenses:
58
72
  metadata:
59
73
  homepage_uri: https://github.com/Alexander-Senko/organizer
60
74
  source_code_uri: https://github.com/Alexander-Senko/organizer
61
- changelog_uri: https://github.com/Alexander-Senko/organizer/blob/v0.1.2/CHANGELOG.md
75
+ changelog_uri: https://github.com/Alexander-Senko/organizer/blob/v0.2.0/CHANGELOG.md
62
76
  post_install_message:
63
77
  rdoc_options: []
64
78
  require_paths:
@@ -74,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  requirements: []
77
- rubygems_version: 3.5.3
91
+ rubygems_version: 3.5.5
78
92
  signing_key:
79
93
  specification_version: 4
80
94
  summary: Record organizer for Rails