worsemodel 0.1.8 → 0.1.9

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
  SHA1:
3
- metadata.gz: d074330251305ee69cd05e357c209ebb80dcec8a
4
- data.tar.gz: 4832c830ee8e8c0ad0ee0c763f57564aa0b12bc5
3
+ metadata.gz: 1ce7f3751966028db5b242d65a3c15f81fc3e21d
4
+ data.tar.gz: 747684787f00a309f9ffbd7de06afc2ff038c147
5
5
  SHA512:
6
- metadata.gz: 00b3db91c19d3a154b032fd9199bee29608a7a5eafd28ba994c6e75d3c28703d8c965338d83d8886c2c221958632894e0067de583428404f540837a440014b5c
7
- data.tar.gz: b11eee3986ed87268bb286d56b212d0e7b6117a9e885f042a3f127cf0dccde0252850fa543f35eecabb3b8350e5282eb01fb4614dbdb8c08f526880fcf3f81c4
6
+ metadata.gz: 5fb68b5801d1a246f064deb4f4dc3c522fb9b2890c41637de62b394c3a5e5d1e40870b3a849e71620279314bd4e396c752c1a59e2f48f71758d9766616a85796
7
+ data.tar.gz: 630967abac0d6b6a5d6a890e2693e2c43f28a89ce4614bf3a525b522d5aa94a0f1018ccebd509a0cc04f69962f5977c1e83e5afd2346dee7547a64d498ad855d
@@ -1,8 +1,10 @@
1
+ require 'securerandom'
2
+
1
3
  module SuperModel
2
4
  module RandomID
3
5
  protected
4
6
  def generate_id
5
- ActiveSupport::SecureRandom.hex(13)
7
+ SecureRandom.hex(13)
6
8
  end
7
9
  end
8
- end
10
+ end
@@ -1,16 +1,11 @@
1
1
  module SuperModel
2
2
  module Validations
3
3
  class UniquenessValidator < ActiveModel::EachValidator
4
- attr_reader :klass
5
-
4
+
6
5
  def validate_each(record, attribute, value)
7
- alternate = klass.find_by_attribute(attribute, value)
6
+ alternate = record.class.find_by_attribute(attribute, value)
8
7
  return unless alternate
9
- record.errors.add(attribute, "must be unique", :default => options[:message])
10
- end
11
-
12
- def setup(klass)
13
- @klass = klass
8
+ record.errors.add(attribute, 'must be unique', default: options[:message])
14
9
  end
15
10
  end
16
11
 
@@ -37,4 +32,4 @@ module SuperModel
37
32
  end
38
33
  end
39
34
  end
40
- end
35
+ end
@@ -1,3 +1,5 @@
1
+ require 'supermodel/validations/uniqueness'
2
+
1
3
  module SuperModel
2
4
  module Validations
3
5
  extend ActiveSupport::Concern
@@ -6,7 +8,7 @@ module SuperModel
6
8
  included do
7
9
  alias_method_chain :save, :validation
8
10
  end
9
-
11
+
10
12
  def save_with_validation(options = nil)
11
13
  perform_validation = case options
12
14
  when Hash
@@ -16,7 +18,7 @@ module SuperModel
16
18
  else
17
19
  options
18
20
  end
19
-
21
+
20
22
  if perform_validation && valid? || !perform_validation
21
23
  save_without_validation
22
24
  true
@@ -28,5 +30,3 @@ module SuperModel
28
30
  end
29
31
  end
30
32
  end
31
-
32
- require "supermodel/validations/uniqueness"
data/supermodel.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'worsemodel'
8
- s.version = "0.1.8"
8
+ s.version = '0.1.9'
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worsemodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw