mappd 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +31 -2
- data/_config.yml +1 -0
- data/lib/mappd/mappd.rb +4 -0
- data/lib/mappd/version.rb +1 -1
- data/spec/mappd_spec.rb +14 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 574ed6b0bba558a7820e7e548eeae31807d073303b1e09babb56b7eea1699e6e
|
4
|
+
data.tar.gz: d46b69b10bc81b168755173aa9bdd29c4bb53e4ff97adc67975463a3b149d635
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55888f03d431890672dc23e6c84c278af871e967025a0fff40861770f0378373b61ce58fa26bdbb1774df69412237a61254a0a302c6f334b7a825362e7130908
|
7
|
+
data.tar.gz: 235deda28eb9a180cb268af319e80a162701f69e32d2d523c45540e430cefbadc00e4e89809c831269fb74fccdb97cd334f2e51efe9c986252d85495be870d4e
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Mappd
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/dan-watson/mappd.svg?branch=master)](https://travis-ci.org/dan-watson/mappd)
|
2
4
|
|
3
5
|
Mappd is a replacement gem for [mini_record](https://github.com/DAddYE/mini_record). Mini record is great and I have been using it for a number of years. Unfortunately the mini_record repo has not been updated in some time. With recent rails upgrades mini_record is not working well.
|
4
6
|
|
@@ -6,6 +8,20 @@ Mappd is designed to work with ActiveRecord 5.2 >.
|
|
6
8
|
|
7
9
|
It's simple to use.
|
8
10
|
|
11
|
+
## Setup
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install mappd
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add to your `Gemfile`:
|
18
|
+
|
19
|
+
```
|
20
|
+
gem 'mappd'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Models
|
24
|
+
|
9
25
|
```ruby
|
10
26
|
class Person < ActiveRecord::Base
|
11
27
|
field :name, :string, null: false, default: ''
|
@@ -17,6 +33,9 @@ class Person < ActiveRecord::Base
|
|
17
33
|
field :external_id, :string, length: 10
|
18
34
|
rename :external_id, :e_id
|
19
35
|
field :e_id, :string, length: 10
|
36
|
+
# Delete a field - the old field and drop could be removed after
|
37
|
+
# migrate! is called
|
38
|
+
drop :name
|
20
39
|
|
21
40
|
# Hooks into belongs_to and creates a country_id column
|
22
41
|
# with an index
|
@@ -56,7 +75,7 @@ Role.migrate!
|
|
56
75
|
|
57
76
|
Hey presto your database has been created with the correct schema.
|
58
77
|
|
59
|
-
|
78
|
+
## Types & Options - Field
|
60
79
|
|
61
80
|
```field :name, :type, options = {}```
|
62
81
|
|
@@ -92,5 +111,15 @@ Available options are (none of these exists by default):
|
|
92
111
|
|
93
112
|
```:comment``` - Specifies the comment for the column. This option is ignored by some backends.
|
94
113
|
|
114
|
+
## Using Rails?
|
95
115
|
|
116
|
+
Create a `mappd.rb` initializer inside `config/initializers` and add the following code to auto migrate rails models on every application restart.
|
96
117
|
|
118
|
+
```ruby
|
119
|
+
Dir.glob('app/models/**/*.rb').each do |file_path|
|
120
|
+
basename = File.basename(file_path, File.extname(file_path))
|
121
|
+
clazz = basename.camelize.constantize
|
122
|
+
next if clazz.abstract_class
|
123
|
+
clazz.migrate! if clazz.ancestors.include?(ActiveRecord::Base)
|
124
|
+
end
|
125
|
+
```
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/lib/mappd/mappd.rb
CHANGED
@@ -12,6 +12,10 @@ module Mappd
|
|
12
12
|
commands << [:rename_column, [table_name, from, to]]
|
13
13
|
end
|
14
14
|
|
15
|
+
def drop(name)
|
16
|
+
commands << [:remove_column, [table_name, name]]
|
17
|
+
end
|
18
|
+
|
15
19
|
def field(name, type = :string, options = {})
|
16
20
|
commands << [:add_column, [table_name, name, type, options]]
|
17
21
|
end
|
data/lib/mappd/version.rb
CHANGED
data/spec/mappd_spec.rb
CHANGED
@@ -31,9 +31,22 @@ RSpec.describe Person, type: :model do
|
|
31
31
|
before(:all) do
|
32
32
|
Person.field(:age, :string)
|
33
33
|
Person.migrate!
|
34
|
+
Person.rename(:age, :ages)
|
35
|
+
Person.migrate!
|
36
|
+
end
|
37
|
+
|
38
|
+
it { should have_db_column(:ages).of_type(:string) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#delete column' do
|
42
|
+
before(:all) do
|
43
|
+
Person.field(:ages, :string)
|
44
|
+
Person.migrate!
|
45
|
+
Person.drop(:ages)
|
46
|
+
Person.migrate!
|
34
47
|
end
|
35
48
|
|
36
|
-
it {
|
49
|
+
it { should_not have_db_column(:ages).of_type(:string) }
|
37
50
|
end
|
38
51
|
end
|
39
52
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mappd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Watson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -36,12 +36,14 @@ files:
|
|
36
36
|
- ".gitignore"
|
37
37
|
- ".rspec"
|
38
38
|
- ".rubocop.yml"
|
39
|
+
- ".travis.yml"
|
39
40
|
- Dockerfile
|
40
41
|
- Gemfile
|
41
42
|
- Gemfile.lock
|
42
43
|
- Guardfile
|
43
44
|
- Makefile
|
44
45
|
- README.md
|
46
|
+
- _config.yml
|
45
47
|
- docker-compose.yml
|
46
48
|
- lib/mappd.rb
|
47
49
|
- lib/mappd/mappd.rb
|