stipa 0.2.4 → 0.2.5

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: 035d22e299975a792e6b72649c0160e6a9af69c1b50f5b529503e35e772f5cf6
4
- data.tar.gz: df2d1f4bd439bb41f008e4468c19c0c9538f56ca820570e3afc46fce7b1f6bc0
3
+ metadata.gz: c13ca91809cf6a4b578b9336b9588f4f544055dab765021a54c822f55281291d
4
+ data.tar.gz: ac20150e5e8528532aebe21cf8f1b6354101cf6a92deeb1fe760cd813ef28841
5
5
  SHA512:
6
- metadata.gz: 23b23d3954f3801027e4c396334cab70e3d3091e0ba4a305f740374172a160d489c7ba91eab9a37274f326c0d616bb0caf0d10e619b4ce0cd2e6f82f215d64da
7
- data.tar.gz: e858a068ada0a89e2a7fb256718679fb55a428c1fd3da570bad18618851f50a922baa4dc015a81ef21d7709952e4569d7741ce2356028536b9efc659fe8f2d9f
6
+ metadata.gz: 84e7a0fd600288d87b0ae3c69510028d39d89f4ce2da788624682b39a608b10b2c43fb071cfbbc59f95199c35376cb9acbf32e13d1cf12651fb40d2c39a0cbe0
7
+ data.tar.gz: 2097c4e81b7fc64049a4bb073c7f0ddb704c2e0916d2f0254214cfffbe904ad16b10b40ddaa1ecc0d16ed5a02b9cf8576b6fc6da511e96894c2ef2cc87b02b74
@@ -35,6 +35,7 @@ module Stipa
35
35
  'controllers/application_controller.rb' => t_application_controller,
36
36
  'controllers/health_controller.rb' => t_health_controller,
37
37
  'models/application_model.rb' => t_application_model,
38
+ 'models/post.rb' => t_sample_model,
38
39
  'db/migrate/001_create_posts.rb' => t_migration_create_posts,
39
40
  }
40
41
  end
@@ -188,19 +188,45 @@ module Stipa
188
188
  <<~RUBY
189
189
  # frozen_string_literal: true
190
190
 
191
+ Sequel::Model.require_valid_table = false
192
+
191
193
  require 'stipa/model'
192
194
 
193
- # Include this in any Sequel::Model subclass to get
194
- # timestamps, UUID, soft delete, and serialization.
195
+ # Base model class providing timestamps, UUID, soft delete,
196
+ # serialization, dirty tracking, and validation helpers.
195
197
  #
196
198
  # Usage:
197
- # class Post < Sequel::Model
198
- # include ApplicationModel
199
+ # class Car < ApplicationModel
199
200
  # end
200
201
 
201
- module ApplicationModel
202
- def self.included(base)
203
- base.include Stipa::Model
202
+ class ApplicationModel < Sequel::Model
203
+ include Stipa::Model
204
+
205
+ # Ensure every subclass maps to its own table (e.g. Car → cars),
206
+ # not to the parent's abstract +application_models+ table.
207
+ def self.inherited(subclass)
208
+ super
209
+ subclass.set_dataset(subclass.implicit_table_name) unless subclass.name.to_s.empty?
210
+ end
211
+ end
212
+
213
+ Sequel::Model.require_valid_table = true
214
+ RUBY
215
+ end
216
+
217
+ def t_sample_model
218
+ <<~RUBY
219
+ # frozen_string_literal: true
220
+
221
+ class Post < ApplicationModel
222
+ def validate
223
+ super
224
+ errors.add(:title, 'is required') if title.to_s.strip.empty?
225
+ errors.add(:slug, 'is required') if slug.to_s.strip.empty?
226
+ end
227
+
228
+ def to_param
229
+ slug
204
230
  end
205
231
  end
206
232
  RUBY
@@ -71,6 +71,7 @@ module Stipa
71
71
  'app/controllers/home_controller.rb' => t_home_controller,
72
72
  'app/controllers/health_controller.rb' => t_health_controller,
73
73
  'app/models/application_model.rb' => t_application_model,
74
+ 'app/models/post.rb' => t_sample_model,
74
75
  'db/migrate/001_create_posts.rb' => t_migration_create_posts,
75
76
  'app/views/layouts/application.html.erb' => t_layout,
76
77
  'app/views/home/index.html.erb' => t_home_index,
@@ -4,8 +4,11 @@ module Stipa
4
4
  module Model
5
5
  module UUID
6
6
  def self.included(base)
7
- base.instance_eval do
8
- before_create { self.id ||= SecureRandom.uuid }
7
+ base.class_eval do
8
+ def before_create
9
+ self.id ||= SecureRandom.uuid
10
+ super
11
+ end
9
12
  end
10
13
  end
11
14
 
data/lib/stipa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stipa
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stipa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jānis Harbs