pliny 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/commands/generator/base.rb +11 -3
- data/lib/pliny/commands/generator/migration.rb +0 -13
- data/lib/pliny/commands/generator.rb +16 -16
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +1 -1
- data/spec/commands/generator/base_spec.rb +32 -62
- data/spec/commands/generator/endpoint_spec.rb +2 -2
- metadata +2 -3
- data/spec/commands/generator/migration_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dbcb16bc8dfd3e1ccf6631213e387368cd0a924
|
4
|
+
data.tar.gz: db1bdaa2c246b5fe2a3209c73810113223fcb336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04092bcc6e1883e1eddfe41ae889011ccd51adfb586d0e67529a439ffbced16f0eb59c8a38b143bd1804e6cdef25c96be6fce27d045f78866207dcd254318eed
|
7
|
+
data.tar.gz: af57c21f2048c3fdec9ea622179f6ea1be80ad32878c43131323449e034385777465db789ee47b4f6251084dbf7cc56372240945605fef1dc80f80987e5ef367
|
@@ -10,17 +10,17 @@ module Pliny::Commands
|
|
10
10
|
attr_reader :name, :stream, :options
|
11
11
|
|
12
12
|
def initialize(name, options = {}, stream = $stdout)
|
13
|
-
@name = name
|
13
|
+
@name = normalize_name(name)
|
14
14
|
@options = options
|
15
15
|
@stream = stream
|
16
16
|
end
|
17
17
|
|
18
18
|
def singular_class_name
|
19
|
-
name.
|
19
|
+
name.singularize.camelize
|
20
20
|
end
|
21
21
|
|
22
22
|
def plural_class_name
|
23
|
-
name.
|
23
|
+
name.pluralize.camelize
|
24
24
|
end
|
25
25
|
|
26
26
|
def field_name
|
@@ -58,6 +58,14 @@ module Pliny::Commands
|
|
58
58
|
f.puts yield
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def normalize_name(name)
|
65
|
+
Array(name).map(&:underscore)
|
66
|
+
.map { |n| n.tr(' ', '_') }
|
67
|
+
.join('_')
|
68
|
+
end
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
@@ -3,24 +3,11 @@ require_relative 'base'
|
|
3
3
|
module Pliny::Commands
|
4
4
|
class Generator
|
5
5
|
class Migration < Base
|
6
|
-
def initialize(name, options = {}, stream = $stdout)
|
7
|
-
super
|
8
|
-
@name = normalize_name(name)
|
9
|
-
end
|
10
|
-
|
11
6
|
def create
|
12
7
|
migration = "./db/migrate/#{Time.now.to_i}_#{name}.rb"
|
13
8
|
write_template('migration.erb', migration)
|
14
9
|
display "created migration #{migration}"
|
15
10
|
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def normalize_name(name)
|
20
|
-
Array(name).map(&:underscore)
|
21
|
-
.map { |n| n.tr(' ', '_') }
|
22
|
-
.join('_')
|
23
|
-
end
|
24
11
|
end
|
25
12
|
end
|
26
13
|
end
|
@@ -3,9 +3,9 @@ require 'thor'
|
|
3
3
|
|
4
4
|
module Pliny::Commands
|
5
5
|
class Generator < Thor
|
6
|
-
desc 'endpoint NAME', 'Generates an endpoint'
|
6
|
+
desc 'endpoint [NAME]', 'Generates an endpoint'
|
7
7
|
method_option :scaffold, type: :boolean, default: false, hide: true
|
8
|
-
def endpoint(name)
|
8
|
+
def endpoint(*name)
|
9
9
|
require_relative 'generator/endpoint'
|
10
10
|
|
11
11
|
ep = Endpoint.new(name, options)
|
@@ -14,8 +14,8 @@ module Pliny::Commands
|
|
14
14
|
ep.create_acceptance_test
|
15
15
|
end
|
16
16
|
|
17
|
-
desc 'mediator NAME', 'Generates a mediator'
|
18
|
-
def mediator(name)
|
17
|
+
desc 'mediator [NAME]', 'Generates a mediator'
|
18
|
+
def mediator(*name)
|
19
19
|
require_relative 'generator/mediator'
|
20
20
|
|
21
21
|
md = Mediator.new(name, options)
|
@@ -31,9 +31,9 @@ module Pliny::Commands
|
|
31
31
|
mg.create
|
32
32
|
end
|
33
33
|
|
34
|
-
desc 'model NAME', 'Generates a model'
|
34
|
+
desc 'model [NAME]', 'Generates a model'
|
35
35
|
method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model'
|
36
|
-
def model(name)
|
36
|
+
def model(*name)
|
37
37
|
require_relative 'generator/model'
|
38
38
|
|
39
39
|
md = Model.new(name, options)
|
@@ -42,18 +42,18 @@ module Pliny::Commands
|
|
42
42
|
md.create_test
|
43
43
|
end
|
44
44
|
|
45
|
-
desc 'scaffold NAME', 'Generates a scaffold of endpoint, model, schema and serializer'
|
45
|
+
desc 'scaffold [NAME]', 'Generates a scaffold of endpoint, model, schema and serializer'
|
46
46
|
method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model'
|
47
47
|
method_option :scaffold, type: :boolean, default: true, hide: true
|
48
|
-
def scaffold(name)
|
49
|
-
endpoint(name)
|
50
|
-
model(name)
|
51
|
-
schema(name)
|
52
|
-
serializer(name)
|
48
|
+
def scaffold(*name)
|
49
|
+
endpoint(*name)
|
50
|
+
model(*name)
|
51
|
+
schema(*name)
|
52
|
+
serializer(*name)
|
53
53
|
end
|
54
54
|
|
55
|
-
desc 'schema NAME', 'Generates a schema'
|
56
|
-
def schema(name)
|
55
|
+
desc 'schema [NAME]', 'Generates a schema'
|
56
|
+
def schema(*name)
|
57
57
|
require_relative 'generator/schema'
|
58
58
|
|
59
59
|
sc = Schema.new(name, options)
|
@@ -61,8 +61,8 @@ module Pliny::Commands
|
|
61
61
|
sc.rebuild
|
62
62
|
end
|
63
63
|
|
64
|
-
desc 'serializer NAME', 'Generates a serializer'
|
65
|
-
def serializer(name)
|
64
|
+
desc 'serializer [NAME]', 'Generates a serializer'
|
65
|
+
def serializer(*name)
|
66
66
|
require_relative 'generator/serializer'
|
67
67
|
|
68
68
|
se = Serializer.new(name, options)
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
@@ -3,100 +3,70 @@ require 'pliny/commands/generator/base'
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Pliny::Commands::Generator::Base do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
let(:model_name) { 'resource_histories' }
|
6
|
+
def generator(name, options = {}, stream = StringIO.new)
|
7
|
+
Pliny::Commands::Generator::Base.new(name, options, stream)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
describe '#name' do
|
11
|
+
it 'generates a normalized name given differents argument formats' do
|
12
|
+
[
|
13
|
+
%w(resource history),
|
14
|
+
'resource history',
|
15
|
+
'resource-history',
|
16
|
+
'resource_history',
|
17
|
+
'ResourceHistory'
|
18
|
+
].each do |argument|
|
19
|
+
actual = generator(argument).name
|
20
|
+
assert_equal 'resource_history', actual
|
21
|
+
end
|
13
22
|
end
|
23
|
+
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
assert_equal 'ResourceHistory', subject.singular_class_name
|
20
|
-
end
|
25
|
+
describe '#singular_class_name' do
|
26
|
+
it 'builds a class name for an endpoint' do
|
27
|
+
actual = generator('resource_histories').singular_class_name
|
28
|
+
assert_equal 'ResourceHistory', actual
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
32
|
describe '#plural_class_name' do
|
25
|
-
let(:model_name) { 'resource_histories' }
|
26
|
-
|
27
33
|
it 'builds a class name for a model' do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
describe 'when name with hypens' do
|
32
|
-
let(:model_name) { 'resource-histories' }
|
33
|
-
|
34
|
-
it 'handles hyphens as underscores' do
|
35
|
-
assert_equal 'ResourceHistories', subject.plural_class_name
|
36
|
-
end
|
34
|
+
actual = generator('resource_histories').plural_class_name
|
35
|
+
assert_equal 'ResourceHistories', actual
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
39
|
describe '#field_name' do
|
41
|
-
let(:model_name) { 'resource_histories' }
|
42
|
-
|
43
40
|
it 'uses the singular form' do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
describe 'when name with hypens' do
|
48
|
-
let(:model_name) { 'resource-histories' }
|
49
|
-
|
50
|
-
it 'handles hyphens as underscores' do
|
51
|
-
assert_equal 'resource_history', subject.field_name
|
52
|
-
end
|
41
|
+
actual = generator('resource_histories').field_name
|
42
|
+
assert_equal 'resource_history', actual
|
53
43
|
end
|
54
44
|
end
|
55
45
|
|
56
46
|
describe '#pluralized_file_name' do
|
57
|
-
let(:model_name) { 'resource_history' }
|
58
|
-
|
59
47
|
it 'uses the plural form' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
describe 'when name with hypens' do
|
64
|
-
let(:model_name) { 'resource-history' }
|
65
|
-
|
66
|
-
it 'handles hyphens as underscores' do
|
67
|
-
assert_equal 'resource_histories', subject.pluralized_file_name
|
68
|
-
end
|
48
|
+
actual = generator('resource_history').pluralized_file_name
|
49
|
+
assert_equal 'resource_histories', actual
|
69
50
|
end
|
70
51
|
|
71
52
|
describe 'when name with slashs' do
|
72
|
-
let(:model_name) { 'resource/history' }
|
73
|
-
|
74
53
|
it 'handles slashs as directory' do
|
75
|
-
|
54
|
+
actual = generator('resource/history').pluralized_file_name
|
55
|
+
assert_equal 'resource/histories', actual
|
76
56
|
end
|
77
57
|
end
|
78
58
|
end
|
79
59
|
|
80
60
|
describe '#table_name' do
|
81
|
-
let(:model_name) { 'resource_history' }
|
82
|
-
|
83
61
|
it 'uses the plural form' do
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
describe 'when name with hypens' do
|
88
|
-
let(:model_name) { 'resource-history' }
|
89
|
-
|
90
|
-
it 'handles hyphens as underscores' do
|
91
|
-
assert_equal 'resource_histories', subject.table_name
|
92
|
-
end
|
62
|
+
actual = generator('resource_history').table_name
|
63
|
+
assert_equal 'resource_histories', actual
|
93
64
|
end
|
94
65
|
|
95
66
|
describe 'when name with slashs' do
|
96
|
-
let(:model_name) { 'resource/history' }
|
97
|
-
|
98
67
|
it 'handles slashs as underscores' do
|
99
|
-
|
68
|
+
actual = generator('resource/history').table_name
|
69
|
+
assert_equal 'resource_histories', actual
|
100
70
|
end
|
101
71
|
end
|
102
72
|
end
|
@@ -3,8 +3,8 @@ require 'pliny/commands/generator/endpoint'
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Pliny::Commands::Generator::Endpoint do
|
6
|
-
subject { Pliny::Commands::Generator::Endpoint.new(
|
7
|
-
let(:
|
6
|
+
subject { Pliny::Commands::Generator::Endpoint.new(endpoint_name, {}, StringIO.new) }
|
7
|
+
let(:endpoint_name) { 'resource_history' }
|
8
8
|
|
9
9
|
describe '#url_path' do
|
10
10
|
it 'builds a URL path' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -436,7 +436,6 @@ files:
|
|
436
436
|
- spec/commands/creator_spec.rb
|
437
437
|
- spec/commands/generator/base_spec.rb
|
438
438
|
- spec/commands/generator/endpoint_spec.rb
|
439
|
-
- spec/commands/generator/migration_spec.rb
|
440
439
|
- spec/commands/generator/schema_spec.rb
|
441
440
|
- spec/commands/generator_spec.rb
|
442
441
|
- spec/commands/updater_spec.rb
|
@@ -475,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
475
474
|
version: '0'
|
476
475
|
requirements: []
|
477
476
|
rubyforge_project:
|
478
|
-
rubygems_version: 2.4.
|
477
|
+
rubygems_version: 2.4.5
|
479
478
|
signing_key:
|
480
479
|
specification_version: 4
|
481
480
|
summary: Basic tooling to support API apps in Sinatra
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'pliny/commands/generator'
|
2
|
-
require 'pliny/commands/generator/migration'
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Pliny::Commands::Generator::Migration do
|
6
|
-
describe '#name' do
|
7
|
-
it 'generates a migration name given differents argument formats' do
|
8
|
-
[
|
9
|
-
%w(add column foo to barz),
|
10
|
-
'add column foo to barz',
|
11
|
-
'add_column_foo_to_barz',
|
12
|
-
'AddColumnFooToBarz'
|
13
|
-
].each do |argument|
|
14
|
-
actual = described_class.new(argument, {}, StringIO.new).name
|
15
|
-
assert_equal 'add_column_foo_to_barz', actual
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|