universal_identifiable 0.0.2 → 0.0.3

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: 57d356a3279a05731606bd16018ade06d8284339
4
- data.tar.gz: b1f2933c79064267a17121992dcd1ef75b204acd
3
+ metadata.gz: 3bc5d482d8dbeb285bec83b006c9433fd0cef381
4
+ data.tar.gz: 9e90ab652ffd0544d54f5564b997efc31b08d20c
5
5
  SHA512:
6
- metadata.gz: 1154a180ee96aa3be95efc3f55f18864ac547d674af617811948091c49521fa001fc5bbb1d5e43f9a3082983dc8e0abad4ea0c8b655783ae47ade4b1f86927c2
7
- data.tar.gz: 6c382e83c10db9db0f27a944059f73b0fbc2f0511f383133cd91c085e82496f280ad6ca8f8e537e1bb2bd2f46696defeb47d672774139ab17c5c581626612c4c
6
+ metadata.gz: 5294c8ca97397018e88770739b39c6e1505bfc3229ff8dab4e03f56d941171791bd68488616f5c23c61e1f63ea35111ee6eb33880c2f35d3a53987e9665b7574
7
+ data.tar.gz: 4d2de664d3b195532e5a92dbaf294ff9a5c589a45baf45bc80418c79186e130f5b9d7a9a7d6b38c2ca38a556ed31bea87d812e99d562434c53d276b053a082ef
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Make your model uniq and identifiable through a readable name.
4
4
  Adds uuids to ActiveRecord models along with validators.
5
5
 
6
+ [![Build Status](https://secure.travis-ci.org/neopoly/universal_identifiable.png?branch=master)](http://travis-ci.org/neopoly/universal_identifiable) [![Gem Version](https://badge.fury.io/rb/universal_identifiable.png)](http://badge.fury.io/rb/universal_identifiable) [![Code Climate](https://codeclimate.com/github/neopoly/universal_identifiable.png)](https://codeclimate.com/github/neopoly/universal_identifiable)
7
+
6
8
  ## Installation
7
9
 
8
10
  Add this line to your application's Gemfile:
@@ -19,7 +21,47 @@ Or install it yourself as:
19
21
 
20
22
  ## Usage
21
23
 
22
- TODO: Write usage instructions here
24
+ Create a migration for your existing model with the built in generator.
25
+
26
+ Example:
27
+ <pre>
28
+ rails g uuid Airport
29
+ </pre>
30
+
31
+ In your model:
32
+
33
+ ```ruby
34
+ class Airport < ActiveRecord::Base
35
+ include UniversalIdentifiable
36
+ end
37
+ ```
38
+ Uuids must be prefixed with the modelname and namespaced with a dot. E.G: "airport.dortmund"
39
+
40
+ Set a uuid like you would with any other attribute:
41
+
42
+ ```ruby
43
+ airport = Airport.new(uuid: "airport.dortmund")
44
+ ```
45
+
46
+ You have access to an unnamespaced uuid by passing the appropriate option:
47
+
48
+ ```ruby
49
+ airport.uuid(namespaced: false)
50
+ => "dortmund"
51
+ airport.uuid
52
+ => "airport.dortmund"
53
+ ```
54
+
55
+ Validators:
56
+
57
+ Two validators are automatically added to your model:
58
+
59
+ ```ruby
60
+ validates :uuid, :presence => true, :uniqueness => true
61
+ ```
62
+ TODO:
63
+
64
+ - Automatically save uuid with corresponding modelname, seperated with namespacer.
23
65
 
24
66
  ## Contributing
25
67
 
@@ -0,0 +1,6 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ add_column :<%= table_name %>, :uuid, :string
4
+ add_index :<%= table_name %>, :uuid, :unique => true
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class UuidGenerator < ActiveRecord::Generators::Base
4
+
5
+ desc "Create a migration to add a uuid to your model. Pass your model name as an argument (required)."
6
+
7
+ def self.source_root
8
+ @source_root ||= File.expand_path('../templates', __FILE__)
9
+ end
10
+
11
+ def generate_migration
12
+ migration_template "uuid_migration.rb.erb", "db/migrate/#{migration_file_name}"
13
+ end
14
+
15
+ private
16
+
17
+ def migration_file_name
18
+ "#{migration_name}.rb"
19
+ end
20
+
21
+ def migration_name
22
+ "add_uuid_to_#{name.underscore.pluralize}"
23
+ end
24
+
25
+ def migration_class_name
26
+ migration_name.camelize
27
+ end
28
+
29
+ end
@@ -1,3 +1,3 @@
1
1
  module UniversalIdentifiable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'rails'
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/spec'
3
4
  require 'universal_identifiable'
@@ -9,9 +9,7 @@ module UniversalIdentifiable
9
9
  end
10
10
 
11
11
  it "is valid" do
12
- assert @identifiable_model.uuid
13
-
14
- @identifiable_model.valid?
12
+ assert @identifiable_model.valid?
15
13
 
16
14
  refute @identifiable_model.errors.full_messages.any? do |message|
17
15
  message.include? "uuid"
@@ -0,0 +1,22 @@
1
+ require "test_helper"
2
+ require 'rails/generators'
3
+ require 'generators/uuid_generator'
4
+
5
+ class UuidGeneratorTest < Rails::Generators::TestCase
6
+
7
+ tests UuidGenerator
8
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
9
+
10
+ setup :prepare_destination
11
+
12
+ test 'create migration' do
13
+ run_generator %w(Airport)
14
+
15
+ assert_migration 'db/migrate/add_uuid_to_airports.rb' do |migration|
16
+ assert_match /class AddUuidToAirports/, migration
17
+ assert_match /add_column :airports, :uuid, :string/, migration
18
+ assert_match /add_index :airports, :uuid, :unique => true/, migration
19
+ end
20
+ end
21
+
22
+ end
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "minitest", "~> 5.0"
23
+ spec.add_development_dependency "minitest-spec-rails"
24
24
  spec.add_development_dependency "sqlite3", "~> 1.3"
25
+ spec.add_development_dependency 'railties'
25
26
  spec.add_runtime_dependency 'activerecord', '>= 3'
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: universal_identifiable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Busold
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-14 00:00:00.000000000 Z
11
+ date: 2013-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: minitest-spec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activerecord
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -93,10 +107,13 @@ files:
93
107
  - LICENSE.txt
94
108
  - README.md
95
109
  - Rakefile
110
+ - lib/generators/templates/uuid_migration.rb.erb
111
+ - lib/generators/uuid_generator.rb
96
112
  - lib/universal_identifiable.rb
97
113
  - lib/universal_identifiable/version.rb
98
114
  - test/test_helper.rb
99
115
  - test/universal_identifier/universal_identifier_test.rb
116
+ - test/universal_identifier/uuid_generator_test.rb
100
117
  - universal_identifiable.gemspec
101
118
  homepage: https://github.com/Kobra-Khan/universal_identifiable
102
119
  licenses:
@@ -125,3 +142,4 @@ summary: Adds uuids to ActiveRecord models along with validators.
125
142
  test_files:
126
143
  - test/test_helper.rb
127
144
  - test/universal_identifier/universal_identifier_test.rb
145
+ - test/universal_identifier/uuid_generator_test.rb