universal_identifiable 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57d356a3279a05731606bd16018ade06d8284339
4
+ data.tar.gz: b1f2933c79064267a17121992dcd1ef75b204acd
5
+ SHA512:
6
+ metadata.gz: 1154a180ee96aa3be95efc3f55f18864ac547d674af617811948091c49521fa001fc5bbb1d5e43f9a3082983dc8e0abad4ea0c8b655783ae47ade4b1f86927c2
7
+ data.tar.gz: 6c382e83c10db9db0f27a944059f73b0fbc2f0511f383133cd91c085e82496f280ad6ca8f8e537e1bb2bd2f46696defeb47d672774139ab17c5c581626612c4c
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea/
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 2.0.0@universal_identifiable --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in universal_identifiable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # UniversalIdentifiable
2
+
3
+ Make your model uniq and identifiable through a readable name.
4
+ Adds uuids to ActiveRecord models along with validators.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'universal_identifiable'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install universal_identifiable
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ desc "Run tests"
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs << "test"
10
+ t.pattern = "test/**/*_test.rb"
11
+ t.verbose = true
12
+ end
@@ -0,0 +1,3 @@
1
+ module UniversalIdentifiable
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ require "universal_identifiable/version"
2
+ require 'active_record'
3
+
4
+ module UniversalIdentifiable
5
+ # sample uuid: 'hotel.ritz'
6
+ # TODO: store underscored modelname as prefix automatically. e.G. '#{modelname}.ritz' when assigning attribute
7
+
8
+ NAMESPACER = "."
9
+
10
+ def self.included(base)
11
+ base.validates :uuid, :presence => true, :uniqueness => true
12
+ end
13
+
14
+ def uuid(options={})
15
+ options[:namespaced] = true if options[:namespaced].nil?
16
+ options[:namespaced] ? read_attribute(:uuid) : short_uuid
17
+ end
18
+
19
+ private
20
+
21
+ def short_uuid
22
+ read_attribute(:uuid).split(NAMESPACER).last
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require 'universal_identifiable'
4
+
5
+ class TestCase < Minitest::Spec
6
+ end
7
+
8
+ class FakeRecord < ActiveRecord::Base
9
+ include UniversalIdentifiable
10
+ end
11
+
12
+ ActiveRecord::Base.establish_connection(
13
+ :adapter => 'sqlite3',
14
+ :database => ':memory:'
15
+ )
16
+
17
+ ActiveRecord::Schema.define do
18
+ self.verbose = false
19
+
20
+ create_table :fake_records, :force => true do |t|
21
+ t.string :uuid
22
+ end
23
+ end
@@ -0,0 +1,51 @@
1
+ require "test_helper"
2
+
3
+ module UniversalIdentifiable
4
+
5
+ class UniversalIdentifiableTest < TestCase
6
+
7
+ before do
8
+ @identifiable_model = FakeRecord.new(:uuid => "airport#{UniversalIdentifiable::NAMESPACER}dortmund")
9
+ end
10
+
11
+ it "is valid" do
12
+ assert @identifiable_model.uuid
13
+
14
+ @identifiable_model.valid?
15
+
16
+ refute @identifiable_model.errors.full_messages.any? do |message|
17
+ message.include? "uuid"
18
+ end
19
+ end
20
+
21
+ it "must have attributes present" do
22
+ @identifiable_model.uuid = nil
23
+ @identifiable_model.valid?
24
+
25
+ assert @identifiable_model.errors.full_messages.any? do |message|
26
+ message.include? "blank"
27
+ end
28
+ end
29
+
30
+ it "must be unique" do
31
+ @identifiable_model.save!
32
+
33
+ new_model = FakeRecord.new
34
+ new_model.uuid = @identifiable_model.uuid
35
+ new_model.valid?
36
+
37
+ assert new_model.errors.full_messages.any? do |message|
38
+ message.include? "taken"
39
+ end
40
+ end
41
+
42
+ it "has different uuid formats" do
43
+ assert_equal "airport#{UniversalIdentifiable::NAMESPACER}dortmund", @identifiable_model.uuid
44
+
45
+ assert_equal "dortmund", @identifiable_model.uuid(:namespaced => false)
46
+ assert_equal "airport#{UniversalIdentifiable::NAMESPACER}dortmund", @identifiable_model.uuid(:namespaced => true)
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'universal_identifiable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "universal_identifiable"
8
+ spec.version = UniversalIdentifiable::VERSION
9
+ spec.authors = ["Andreas Busold"]
10
+ spec.email = ["an.bu@gmx.net"]
11
+ spec.description = %q{Make your model uniq and identifiable through a readable name.}
12
+ spec.summary = %q{Adds uuids to ActiveRecord models along with validators.}
13
+ spec.homepage = "https://github.com/Kobra-Khan/universal_identifiable"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+ spec.add_development_dependency "sqlite3", "~> 1.3"
25
+ spec.add_runtime_dependency 'activerecord', '>= 3'
26
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: universal_identifiable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Andreas Busold
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ description: Make your model uniq and identifiable through a readable name.
84
+ email:
85
+ - an.bu@gmx.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rvmrc
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/universal_identifiable.rb
97
+ - lib/universal_identifiable/version.rb
98
+ - test/test_helper.rb
99
+ - test/universal_identifier/universal_identifier_test.rb
100
+ - universal_identifiable.gemspec
101
+ homepage: https://github.com/Kobra-Khan/universal_identifiable
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.0
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Adds uuids to ActiveRecord models along with validators.
125
+ test_files:
126
+ - test/test_helper.rb
127
+ - test/universal_identifier/universal_identifier_test.rb