activerecord-propertybase_id 0.1.0

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: 4482c6bf93ce91a8badf8882964dcc5884dda017
4
+ data.tar.gz: b19fec208329f02aa6c4a400a779b2b66432bb75
5
+ SHA512:
6
+ metadata.gz: d798f4c99982ecaa66efa91d32b785af144d7bedce6a9ec7e69a03bedb5eed898153077a30e58beab2a3fd396921d8c2f953b765daa753047c10a882f8c316fa
7
+ data.tar.gz: 4239c047ad3058046e810bce8aee9d865c8099c1b1d807716590d8223dc489ec9ad153acc65223128b53d109a6b98872a53be95fd79ed547e93f6564ff9b3356
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/debug.log
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.5
5
+ - 2.2.1
6
+ - rbx
7
+ - ruby-head
8
+ - jruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ - rvm: jruby-head
13
+ matrix:
14
+ fast_finish: true
15
+ addons:
16
+ postgresql: "9.4"
17
+ env:
18
+ - DB=sqlite3
19
+ - DB=postgresql
20
+ script:
21
+ - bundle exec rspec
22
+ before_script:
23
+ - gem update bundler
24
+ - psql -c 'create database propertybase_id_test;' -U postgres
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-propertybase_id.gemspec
4
+ gemspec
5
+
6
+ gem "guard"
7
+ gem "guard-rspec"
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ # Standard RubyGem Project
16
+ watch(/^spec\/.+_spec\.rb/)
17
+ watch(/^lib\/(.+)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
18
+ watch("spec/spec_helper.rb") { "spec" }
19
+ end
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # ActiveRecord::PropertybaseId
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activerecord/propertybase_id`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "activerecord-propertybase_id"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install activerecord-propertybase_id
22
+
23
+ ## Usage
24
+
25
+ This ActiveRecord extension lets you use the [Propertybase ID](https://github.com/propertybase/propertybase_id) as a primary key in Rails.
26
+
27
+ ### Migration
28
+
29
+ The Propertybase ID is stored via the `char(8)` data type (currently only tested on SQLite and PostgreSQL). You can also use the cusom migration type `propertybase_id`.
30
+
31
+ Note: As Rails doesn't really support changing the type of the primary key in the migration. You need to work around a little bit. You need to disable the ID for a sepcific table and then add it as
32
+
33
+ ```ruby
34
+ class CreateTeams < ActiveRecord::Migration
35
+ def change
36
+ create_table :teams, id: false do |t|
37
+ t.propertybase_id :id, primary_key: true
38
+
39
+ t.string :name
40
+ t.timestamps null: false
41
+ end
42
+ end
43
+ end
44
+ ```
45
+
46
+ You are now all set to use the Propertybase ID as the primary key of your table.
47
+
48
+ ### ActiveRecord Models
49
+
50
+ To make sure the ID is generated, you need to include the `ActiveRecord::PropertybaseId` module:
51
+
52
+ ```ruby
53
+ class Team < ActiveRecord::Base
54
+ include ActiveRecord::PropertybaseId
55
+ end
56
+ ```
57
+
58
+ The PropertybaseId need the object type as input. By default the object type will be inferred by the model name (currently only Team and User working), but you override it by specifying `propertybase_object`
59
+
60
+ ```ruby
61
+ class CustomizedUser < ActiveRecord::Base
62
+ include ActiveRecord::PropertybaseId
63
+
64
+ propertybase_object :user
65
+ end
66
+ ```
67
+
68
+ ## Caveats
69
+
70
+ Currently this gem only has been tested on PostgreSQL and SQLite and Rails version 4.2
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+
78
+ ## Atribution
79
+
80
+ Heavily inspired by [activeuuid](https://github.com/jashmenn/activeuuid).
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it ( https://github.com/[my-github-username]/activerecord-propertybase_id/fork )
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "activerecord/propertybase_id/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord-propertybase_id"
8
+ spec.version = ActiveRecord::PropertybaseId::VERSION
9
+ spec.authors = ["Leif Gensert"]
10
+ spec.email = ["leif@propertybase.com"]
11
+
12
+ spec.summary = %q{Propertybase ID for ActiveRecord}
13
+ spec.description = %q{Use the propertybase_id as the primary key in all your rails models}
14
+ spec.homepage = "http://www.propertybase.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "propertybase_id", ">= 0.3.3"
22
+ spec.add_dependency "activerecord", ">= 4.2", "< 4.3"
23
+
24
+ spec.add_development_dependency "bundler", "< 1.10"
25
+ spec.add_development_dependency "rake", "< 11.0"
26
+ spec.add_development_dependency "rspec", "< 3.3"
27
+ if defined?(JRUBY_VERSION)
28
+ spec.add_development_dependency "activerecord-jdbc-adapter", "< 1.4"
29
+ spec.add_development_dependency "jdbc-postgres", "< 9.5"
30
+ spec.add_development_dependency "jdbc-sqlite3", "< 3.9"
31
+ else
32
+ spec.add_development_dependency "pg", "< 0.19"
33
+ spec.add_development_dependency "sqlite3", "< 1.4.0"
34
+ end
35
+ spec.add_development_dependency "database_cleaner", "< 1.5.0"
36
+ spec.add_development_dependency "rspec-its", "< 1.3.0"
37
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "activerecord/propertybase_id"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ require "propertybase_id"
2
+ require "active_record"
3
+ require "active_support/concern"
4
+ require "activerecord/propertybase_id/version"
5
+ require "activerecord/propertybase_id/patches"
6
+ require "activerecord/propertybase_id/railtie" if defined?(Rails::Railtie)
7
+
8
+ module ActiveRecord
9
+ module PropertybaseId
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ class_attribute :_propertybase_object, instance_writer: false
14
+ self._propertybase_object = self.name.underscore
15
+
16
+ before_create :generate_propertybase_id_if_needed
17
+ end
18
+
19
+ def propertybase_id
20
+ pb_id_string = send(self.class.primary_key)
21
+ ::PropertybaseId.parse(pb_id_string)
22
+ end
23
+
24
+ def generate_propertybase_id
25
+ ::PropertybaseId.generate(object: _propertybase_object.to_s).to_s
26
+ end
27
+
28
+ def generate_propertybase_id_if_needed
29
+ primary_key = self.class.primary_key
30
+ send("#{primary_key}=", generate_propertybase_id) unless send("#{primary_key}?")
31
+ end
32
+
33
+ module ClassMethods
34
+ def propertybase_object(proeprtybase_object)
35
+ self._propertybase_object = proeprtybase_object
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ ActiveRecord::PropertybaseId::Patches.apply!
@@ -0,0 +1,21 @@
1
+ module ActiveRecord
2
+ module PropertybaseId
3
+ module Patches
4
+ module Migrations
5
+ def propertybase_id(*column_names)
6
+ options = column_names.extract_options!
7
+ column_names.each do |name|
8
+ type = "char(#{::PropertybaseId.max_length})"
9
+ primary_key = options.delete(:primary_key) || name.to_s == "id"
10
+ column(name, "#{type}#{' PRIMARY KEY' if primary_key}", options)
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.apply!
16
+ ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table
17
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ require "activerecord/propertybase_id"
2
+ require "rails"
3
+
4
+ module ActiveRecord
5
+ module PropertybaseId
6
+ class Railtie < Rails::Railtie
7
+ railtie_name :propertybase_id
8
+
9
+ config.to_prepare do
10
+ ActiveRecord::PropertybaseId::Patches.apply!
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module PropertybaseId
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-propertybase_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Leif Gensert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: propertybase_id
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '4.3'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.2'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.10'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '11.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '11.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "<"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.3'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.3'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pg
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "<"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.19'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.19'
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "<"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.4.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: 1.4.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: database_cleaner
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "<"
122
+ - !ruby/object:Gem::Version
123
+ version: 1.5.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "<"
129
+ - !ruby/object:Gem::Version
130
+ version: 1.5.0
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec-its
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "<"
136
+ - !ruby/object:Gem::Version
137
+ version: 1.3.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: 1.3.0
145
+ description: Use the propertybase_id as the primary key in all your rails models
146
+ email:
147
+ - leif@propertybase.com
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - ".gitignore"
153
+ - ".rspec"
154
+ - ".travis.yml"
155
+ - CODE_OF_CONDUCT.md
156
+ - Gemfile
157
+ - Guardfile
158
+ - README.md
159
+ - Rakefile
160
+ - activerecord-propertybase_id.gemspec
161
+ - bin/console
162
+ - bin/setup
163
+ - lib/activerecord/propertybase_id.rb
164
+ - lib/activerecord/propertybase_id/patches.rb
165
+ - lib/activerecord/propertybase_id/railtie.rb
166
+ - lib/activerecord/propertybase_id/version.rb
167
+ homepage: http://www.propertybase.com
168
+ licenses: []
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.4.5
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: Propertybase ID for ActiveRecord
190
+ test_files: []