in_time_scope 0.1.0 → 0.1.2

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.

Potentially problematic release.


This version of in_time_scope might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eee76cde212cee461aa7b915b048c5479bc1adc82faa1a57fc4d10e136806eb6
4
- data.tar.gz: b6de2422411c951e2e1cf3029498755b77c9de73731ed9e24d3d20c0df612d79
3
+ metadata.gz: 7ae5a251a71cec0f0ad9ac7890d9e1e88de46dade545cbfcff2cf0201d603939
4
+ data.tar.gz: 9a4c17e7f1ad5a1b62ebf37038332d43a7610fcce5f770e66df70e51670dc415
5
5
  SHA512:
6
- metadata.gz: 9d9daa7dc0815efde3c0d6a0d6231da6799526fa17be1c96bc22cb76f460ce7e4c84f40ae449760a5e24e86177632b174c94ecf13ec0d3240cae9c4a39ad5721
7
- data.tar.gz: 337490e629eca19edec0fe0615ee895f67e475258281a173c61e10cf8014a4f185ae72c48fbc07065d7ae29c0b6e9016b547827b83556a4d8c6be3c79c95ec04
6
+ metadata.gz: 4480bbfaee296c29a87e96b26c2f32f29a78792712765cb48b51699c01bc552526ab1764972bd6cb19bfa4ce5de115abd099a7d0abf8701a26fa69eedc780d6e
7
+ data.tar.gz: b905e3bf65da95f7b4868e49c386051616b071cd67de613617d0443caa4679cbb4cc0c729ca9b6ec2776a32af4cfda32deedd48d61ceca4d326c833748b382a4
data/README.md CHANGED
@@ -87,11 +87,12 @@ Use these options in `in_time_scope` to customize column behavior.
87
87
 
88
88
  | Option | Applies to | Type | Default | Description | Example |
89
89
  | --- | --- | --- | --- | --- | --- |
90
- | `:scope_name` (1st arg) | in_time | `Symbol` | `:in_time` | Creates a named scope like `published_in_time` | `in_time_scope :published` |
90
+ | `:scope_name` (1st arg) | in_time | `Symbol` | `:in_time` | Creates a named scope like `in_time_published` | `in_time_scope :published` |
91
91
  | `start_at: { column: ... }` | start_at | `Symbol` / `nil` | `:start_at` (or `:"<scope>_start_at"` when `:scope_name` is set) | Use a custom column name; set `nil` to disable `start_at` | `start_at: { column: :available_at }` |
92
92
  | `end_at: { column: ... }` | end_at | `Symbol` / `nil` | `:end_at` (or `:"<scope>_end_at"` when `:scope_name` is set) | Use a custom column name; set `nil` to disable `end_at` | `end_at: { column: nil }` |
93
93
  | `start_at: { null: ... }` | start_at | `true/false` | auto (schema) | Force NULL-aware vs NOT NULL behavior | `start_at: { null: false }` |
94
94
  | `end_at: { null: ... }` | end_at | `true/false` | auto (schema) | Force NULL-aware vs NOT NULL behavior | `end_at: { null: true }` |
95
+ | `prefix: true` | scope_name | `true/false` | `false` | Use prefix style method name like `published_in_time` instead of `in_time_published` | `in_time_scope :published, prefix: true` |
95
96
 
96
97
  ### Alternative: Start-Only History (No `end_at`)
97
98
  Use this when periods never overlap and you want exactly one "current" row.
@@ -175,8 +176,8 @@ Customize which columns are used and define more than one time window per model.
175
176
  create_table :events do |t|
176
177
  t.datetime :available_at, null: true
177
178
  t.datetime :expired_at, null: true
178
- t.datetime :publish_start_at, null: false
179
- t.datetime :publish_end_at, null: false
179
+ t.datetime :published_start_at, null: false
180
+ t.datetime :published_end_at, null: false
180
181
 
181
182
  t.timestamps
182
183
  end
@@ -187,15 +188,30 @@ class Event < ActiveRecord::Base
187
188
  # Use different column names
188
189
  in_time_scope start_at: { column: :available_at }, end_at: { column: :expired_at }
189
190
 
190
- # Define an additional scope
191
- in_time_scope :published, start_at: { column: :publish_start_at, null: false }, end_at: { column: :publish_end_at, null: false }
191
+ # Define an additional scope - uses published_start_at / published_end_at by default
192
+ in_time_scope :published
192
193
  end
193
194
 
194
195
  Event.in_time
195
196
  # => uses available_at / expired_at
196
197
 
198
+ Event.in_time_published
199
+ # => uses published_start_at / published_end_at
200
+ ```
201
+
202
+ ### Using `prefix: true` Option
203
+ Use the `prefix: true` option if you prefer the scope name as a prefix instead of suffix.
204
+
205
+ ```ruby
206
+ class Event < ActiveRecord::Base
207
+ include InTimeScope
208
+
209
+ # With prefix: true, the method name becomes published_in_time instead of in_time_published
210
+ in_time_scope :published, prefix: true
211
+ end
212
+
197
213
  Event.published_in_time
198
- # => uses publish_start_at / publish_end_at
214
+ # => uses published_start_at / published_end_at
199
215
  ```
200
216
 
201
217
  ### Using with `has_one` Associations
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InTimeScope
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/in_time_scope.rb CHANGED
@@ -11,23 +11,22 @@ module InTimeScope
11
11
  end
12
12
 
13
13
  module ClassMethods
14
- def in_time_scope(scope_name = nil, start_at: {}, end_at: {})
14
+ def in_time_scope(scope_name = nil, start_at: {}, end_at: {}, prefix: false)
15
15
  scope_name ||= :in_time
16
- scope_suffix = scope_name == :in_time ? "" : "_#{scope_name}"
16
+ scope_prefix = scope_name == :in_time ? "" : "#{scope_name}_"
17
17
 
18
- start_config = normalize_config(start_at, :"start_at#{scope_suffix}", :start_at)
19
- end_config = normalize_config(end_at, :"end_at#{scope_suffix}", :end_at)
18
+ start_config = normalize_config(start_at, :"#{scope_prefix}start_at")
19
+ end_config = normalize_config(end_at, :"#{scope_prefix}end_at")
20
20
 
21
- define_scope_methods(scope_name, start_config, end_config)
21
+ define_scope_methods(scope_name, start_config, end_config, prefix)
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def normalize_config(config, default_column, fallback_column)
26
+ def normalize_config(config, default_column)
27
27
  return { column: nil, null: true } if config[:column].nil? && config.key?(:column)
28
28
 
29
29
  column = config[:column] || default_column
30
- column = fallback_column unless column_names.include?(column.to_s)
31
30
  column = nil unless column_names.include?(column.to_s)
32
31
 
33
32
  null = config.key?(:null) ? config[:null] : column_nullable?(column)
@@ -42,8 +41,14 @@ module InTimeScope
42
41
  col ? col.null : true
43
42
  end
44
43
 
45
- def define_scope_methods(scope_name, start_config, end_config)
46
- method_name = scope_name == :in_time ? :in_time : :"#{scope_name}_in_time"
44
+ def define_scope_methods(scope_name, start_config, end_config, prefix)
45
+ method_name = if scope_name == :in_time
46
+ :in_time
47
+ elsif prefix
48
+ :"#{scope_name}_in_time"
49
+ else
50
+ :"in_time_#{scope_name}"
51
+ end
47
52
  instance_method_name = :"#{method_name}?"
48
53
 
49
54
  start_column = start_config[:column]
@@ -89,7 +94,7 @@ module InTimeScope
89
94
  end
90
95
 
91
96
  def define_latest_scope(method_name, start_column, start_null)
92
- latest_method_name = method_name == :in_time ? :latest_in_time : :"latest_#{method_name}_in_time"
97
+ latest_method_name = method_name == :in_time ? :latest_in_time : :"latest_#{method_name}"
93
98
  tbl = table_name
94
99
  col = start_column
95
100
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_time_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyohah
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-01-24 00:00:00.000000000 Z
10
+ date: 2026-01-29 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord