in_time_scope 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12b5f84b69262b47ea6936b0658151404805b938061fd0c91e080a1a4f435125
4
- data.tar.gz: fe4cde1d907cb57e1562f551336db91ae43b30a22d2c3db6dd11e3a3eb3202e3
3
+ metadata.gz: c5ab9dff9b5a5abce4d0418d2a8ec3895126a910a0926f1a449fc55bad3cebd4
4
+ data.tar.gz: '082a9f889d860c0dc7f587fafb77baaa932ccc864e8dfe06b10b92ab9644308a'
5
5
  SHA512:
6
- metadata.gz: 2f8766dad406ddfa8317afa597bf67fdbc2e2f1a4c7f437be46540f315f3359daf4cf8dfac317d4e36647597fe3aace454ad1549e50def596585503026305366
7
- data.tar.gz: 0d53d1b56ebcd19b97e3a4af9f498a676ed31bd0d61b37d22ebf1d572ad7b591a86a670ea5e2adf40fd0122495362e7026dbd696b5631857edef447879a9350c
6
+ metadata.gz: 7df8620094c225af106a3ed909dfa3af5abd328630e1a571cbe0943ecf5a8f965bc1c56286493181305a44fc87a148b055247c12291ee9110b49ca700b45b1bc
7
+ data.tar.gz: 7dc373ec631d291cbdb9c73acaec4bc21d5271495a1131681a3a8aa6929480a28a886010eb3bcc209951825b5c92590a13730aae7ec119a09d96fb66d17f8218
data/README.md CHANGED
@@ -277,16 +277,16 @@ The `earliest_in_time(:foreign_key)` scope uses a `NOT EXISTS` subquery to find
277
277
 
278
278
  ### Error Handling
279
279
 
280
- If you specify a scope name but the expected columns don't exist, an error is raised at class load time:
280
+ If you specify a scope name but the expected columns don't exist, a `ColumnNotFoundError` is raised at class load time:
281
281
 
282
282
  ```ruby
283
283
  class Event < ActiveRecord::Base
284
284
  include InTimeScope
285
285
 
286
- # This will raise NoMethodError if hoge_start_at or hoge_end_at columns don't exist
286
+ # This will raise ColumnNotFoundError if hoge_start_at or hoge_end_at columns don't exist
287
287
  in_time_scope :hoge
288
288
  end
289
- # => NoMethodError: undefined method `null' for nil:NilClass
289
+ # => InTimeScope::ColumnNotFoundError: Column 'hoge_start_at' does not exist on table 'events'
290
290
  ```
291
291
 
292
292
  This helps catch configuration errors early during development.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InTimeScope
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/in_time_scope.rb CHANGED
@@ -5,6 +5,8 @@ require_relative "in_time_scope/version"
5
5
 
6
6
  module InTimeScope
7
7
  class Error < StandardError; end
8
+ class ColumnNotFoundError < Error; end
9
+ class ConfigurationError < Error; end
8
10
 
9
11
  def self.included(model)
10
12
  model.extend ClassMethods
@@ -18,8 +20,8 @@ module InTimeScope
18
20
  start_at_column = start_at.fetch(:column, :"#{time_column_prefix}start_at")
19
21
  end_at_column = end_at.fetch(:column, :"#{time_column_prefix}end_at")
20
22
 
21
- start_at_null = start_at.fetch(:null, table_column_hash[start_at_column.to_s].null) unless start_at_column.nil?
22
- end_at_null = end_at.fetch(:null, table_column_hash[end_at_column.to_s].null) unless end_at_column.nil?
23
+ start_at_null = fetch_null_option(start_at, start_at_column, table_column_hash)
24
+ end_at_null = fetch_null_option(end_at, end_at_column, table_column_hash)
23
25
 
24
26
  scope_method_name = method_name(scope_name, prefix)
25
27
 
@@ -28,6 +30,16 @@ module InTimeScope
28
30
 
29
31
  private
30
32
 
33
+ def fetch_null_option(config, column, table_column_hash)
34
+ return nil if column.nil?
35
+ return config[:null] if config.key?(:null)
36
+
37
+ column_info = table_column_hash[column.to_s]
38
+ raise ColumnNotFoundError, "Column '#{column}' does not exist on table '#{table_name}'" if column_info.nil?
39
+
40
+ column_info.null
41
+ end
42
+
31
43
  def method_name(scope_name, prefix)
32
44
  return :in_time if scope_name == :in_time
33
45
 
@@ -38,7 +50,7 @@ module InTimeScope
38
50
  # Define class-level scope
39
51
  if start_at_column.nil? && end_at_column.nil?
40
52
  # Both disabled - return all
41
- scope scope_method_name, ->(_time = Time.current) { raise ArgumentError, "At least one of start_at or end_at must be specified." }
53
+ raise ConfigurationError, "At least one of start_at or end_at must be specified"
42
54
  elsif end_at_column.nil?
43
55
  # Start-only pattern (history tracking)
44
56
  define_start_only_scope(scope_method_name, start_at_column, start_at_null)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_time_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyohah