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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc337a411672ab3426ea52e47a29e0ff26b584ca6d208d575de6d520c3e29527
4
- data.tar.gz: d0afa522e277f482ea096303adcccffd08fffa30031c9c545beb26e83b38492e
3
+ metadata.gz: 574ed6b0bba558a7820e7e548eeae31807d073303b1e09babb56b7eea1699e6e
4
+ data.tar.gz: d46b69b10bc81b168755173aa9bdd29c4bb53e4ff97adc67975463a3b149d635
5
5
  SHA512:
6
- metadata.gz: 0b71039911641f03c1d4d3a70637e802fe2806c9eb1816a60907419bd387ba5aefef87da63438e14bb9caeaaf38d31e68194519ca32b5d33adabfc03383d29ca
7
- data.tar.gz: fe8a0e6430f2642ef22fb0909c9e2c215fd557b83612a16de5c35a258797183dce12e997665f458683d580ce4298627f4aa7569dbb17e7f7cbd5b40ef2fee738
6
+ metadata.gz: 55888f03d431890672dc23e6c84c278af871e967025a0fff40861770f0378373b61ce58fa26bdbb1774df69412237a61254a0a302c6f334b7a825362e7130908
7
+ data.tar.gz: 235deda28eb9a180cb268af319e80a162701f69e32d2d523c45540e430cefbadc00e4e89809c831269fb74fccdb97cd334f2e51efe9c986252d85495be870d4e
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5
4
+ install:
5
+ - bundle install
6
+ script:
7
+ - bundle exec rubocop
8
+ - bundle exec rspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mappd (0.0.3)
4
+ mappd (0.0.4)
5
5
  activerecord (>= 5.2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # README
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
- # Types & Options - Field
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
+ ```
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mappd
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
@@ -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 { should have_db_column(:age).of_type(:string) }
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.3
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-15 00:00:00.000000000 Z
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