grape-starter 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/grape-starter +6 -6
- data/lib/starter/builder/names.rb +4 -0
- data/lib/starter/builder.rb +38 -12
- data/lib/starter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48b2d656a0abf765b24c458a64d4d3a973a02f47
|
4
|
+
data.tar.gz: c094ccfd1860944a60aa8090dd0fec4a7c3cfd33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d7783455e1d96a48e752ab6ec0e5a14bcb8506b4cdd66151e707821421e0c1162b7dc94eb9301838a166691cabb14997a7769e24ce657042494acd9718d1afc
|
7
|
+
data.tar.gz: 1c96c6d62e6b1356ab8d3195a282f5236c9f86bcb8ee4078d30a47f6dbdefe9b6286121b4bb73c01fd047cb503a24954f1d22cf104697e70eeb27c11d38678b7
|
data/README.md
CHANGED
@@ -59,14 +59,14 @@ More could be found in [README](template/README.md).
|
|
59
59
|
```
|
60
60
|
$ grape-starter add foo
|
61
61
|
```
|
62
|
-
to add CRUD endpoints for resource foo. For more options, see
|
62
|
+
to add CRUD endpoints for resource foo. For more options, see `grape-starter add -h`.
|
63
63
|
|
64
64
|
This adds endpoint and lib file and belonging specs, and a mount entry in base.rb.
|
65
65
|
|
66
66
|
|
67
67
|
#### Remove a resource
|
68
68
|
```
|
69
|
-
$ grape-starter
|
69
|
+
$ grape-starter rm foo
|
70
70
|
```
|
71
71
|
to remove previous generated files for a resource.
|
72
72
|
|
data/bin/grape-starter
CHANGED
@@ -41,7 +41,6 @@ command :new do |c|
|
|
41
41
|
FileUtils.copy_entry src, dir
|
42
42
|
|
43
43
|
FileUtils.cd(dir) do
|
44
|
-
# TODO:
|
45
44
|
$stdout.puts `bundle install`
|
46
45
|
$stdout.puts `bundle exec rubocop -a`
|
47
46
|
$stdout.puts `git init`
|
@@ -50,10 +49,11 @@ command :new do |c|
|
|
50
49
|
end
|
51
50
|
|
52
51
|
desc 'Adds a new resource - run from inside the project'
|
53
|
-
long_desc "
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
long_desc "
|
53
|
+
params: \n
|
54
|
+
resource - to add, it respects the numerus of it (required)\n
|
55
|
+
http_verbs - specify which end-points should be created, if nothings given CRUD would be writen
|
56
|
+
"
|
57
57
|
arg_name 'resource [post* get* put* patch* delete*]'
|
58
58
|
command :add do |c|
|
59
59
|
c.desc 'adds entity file'
|
@@ -69,7 +69,7 @@ command :add do |c|
|
|
69
69
|
builder_options = global_options.merge(set: set).merge(options)
|
70
70
|
Starter::Builder.call!(resource, builder_options)
|
71
71
|
created_files = Starter::Builder.save
|
72
|
-
|
72
|
+
|
73
73
|
`bundle exec rubocop -a #{created_files.join(' ')}`
|
74
74
|
$stdout.puts "added resource: #{resource}"
|
75
75
|
rescue => e
|
data/lib/starter/builder.rb
CHANGED
@@ -30,6 +30,7 @@ module Starter
|
|
30
30
|
file_list.map { |x| send("#{x}_name") }.each do |file_to_remove|
|
31
31
|
begin
|
32
32
|
FileUtils.rm file_to_remove
|
33
|
+
remove_mount_point
|
33
34
|
rescue => error
|
34
35
|
$stdout.puts error.to_s
|
35
36
|
end
|
@@ -42,7 +43,7 @@ module Starter
|
|
42
43
|
save_file(new_file)
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
+
add_mount_point
|
46
47
|
|
47
48
|
created_files
|
48
49
|
end
|
@@ -63,30 +64,55 @@ module Starter
|
|
63
64
|
entity ? standards + ['entity_file'] : standards
|
64
65
|
end
|
65
66
|
|
67
|
+
def should_raise?(file)
|
68
|
+
raise StandardError, '… resource exists' if File.exist?(file) && !force
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_mount_point
|
72
|
+
file = read_file(api_base_file_name)
|
73
|
+
add_to_base(file)
|
74
|
+
write_file(api_base_file_name, file)
|
75
|
+
end
|
76
|
+
|
77
|
+
def remove_mount_point
|
78
|
+
file = read_file(api_base_file_name)
|
79
|
+
remove_from_base(file)
|
80
|
+
write_file(api_base_file_name, file)
|
81
|
+
end
|
82
|
+
|
66
83
|
def save_file(new_file)
|
67
84
|
new_file_name = "#{new_file}_name"
|
68
85
|
should_raise?(send(new_file_name))
|
69
86
|
|
70
|
-
|
87
|
+
write_file(send(new_file_name), send(new_file.strip_heredoc))
|
71
88
|
end
|
72
89
|
|
73
|
-
def
|
74
|
-
|
90
|
+
def endpoint_set
|
91
|
+
crud_set = singular? ? singular_one : crud
|
92
|
+
return crud_set if set.blank?
|
93
|
+
|
94
|
+
crud_set.each_with_object([]) { |x, memo| set.map { |y| memo << x if x.to_s.start_with?(y) } }
|
75
95
|
end
|
76
96
|
|
77
|
-
|
78
|
-
|
97
|
+
# manipulating API Base file
|
98
|
+
# … adding
|
99
|
+
def add_to_base(file)
|
79
100
|
occurence = file.scan(/(\s+mount.*?\n)/).last.first
|
80
|
-
replacement = occurence +
|
101
|
+
replacement = occurence + mount_point
|
81
102
|
file.sub!(occurence, replacement)
|
82
|
-
File.open(api_base_file_name, 'w') { |f| f.write(file) }
|
83
103
|
end
|
84
104
|
|
85
|
-
|
86
|
-
|
87
|
-
|
105
|
+
# … removing
|
106
|
+
def remove_from_base(file)
|
107
|
+
file.sub!(mount_point, '')
|
108
|
+
end
|
88
109
|
|
89
|
-
|
110
|
+
def read_file(file)
|
111
|
+
File.read(file)
|
112
|
+
end
|
113
|
+
|
114
|
+
def write_file(file, content)
|
115
|
+
File.open(file, 'w') { |f| f.write(content) }
|
90
116
|
end
|
91
117
|
|
92
118
|
def content(set)
|
data/lib/starter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-starter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeFnord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|