has_hashcode 0.1.0 → 0.1.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/has_hashcode.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_hashcode}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Elomar Fran\303\247a", "Rafael Souza"]
data/lib/has_hashcode.rb CHANGED
@@ -4,21 +4,19 @@ module HasHashcode
4
4
 
5
5
  initializer "railtie_name.hook_into_active_record" do
6
6
  ActiveRecord.base_hook do
7
- extend HasHashcode
7
+ include HasHashcode
8
8
  end
9
9
  end
10
10
  end
11
11
 
12
- def has_hashcode
13
- class_eval do
14
- def generate_hashcode
15
- begin
16
- self.hashcode = ActiveSupport::SecureRandom.hex(3).upcase
17
- end while !valid? && errors.on(:hashcode).present?
18
- end
19
- end
20
-
12
+ def self.has_hashcode
21
13
  before_create :generate_hashcode
22
14
  validates_uniqueness_of :hashcode, :allow_nil => true
23
15
  end
16
+
17
+ def generate_hashcode
18
+ begin
19
+ self.hashcode = ActiveSupport::SecureRandom.hex(3).upcase
20
+ end while !valid? && errors[:hashcode].present?
21
+ end
24
22
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Elomar Fran\xC3\xA7a"