Skip to content

Commit

Permalink
Make using uuid as param configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmetal committed May 23, 2017
1 parent 3e97aaa commit bc5a223
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Metrics/LineLength:
Max: 120

Metrics/CyclomaticComplexity:
Max: 10

Metrics/MethodLength:
Max: 20

Metrics/AbcSize:
Max: 25
10 changes: 6 additions & 4 deletions lib/uuidable/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ def find(*args)
end
end

def uuidable
after_initialize { self.uuid = Uuidable.generate_uuid if uuid.blank? }
def uuidable(as_param: true)
after_initialize { self.uuid = Uuidable.generate_uuid if attributes.keys.include?('uuid') && uuid.blank? }
validates :uuid, presence: true, uniqueness: true

define_method :to_param do
uuid
if as_param
define_method :to_param do
uuid
end
end

define_method :uuid= do |val|
Expand Down
2 changes: 1 addition & 1 deletion lib/uuidable/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Uuidable
VERSION = '0.1.1'.freeze
VERSION = '0.1.2'.freeze
end

0 comments on commit bc5a223

Please sign in to comment.