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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 790b8b35a17bfad2d7d24f930e1890070a2ec310
4
- data.tar.gz: 1c206bc897cb55fe92a9cea52ad9edcb0b2abebe
3
+ metadata.gz: 48b2d656a0abf765b24c458a64d4d3a973a02f47
4
+ data.tar.gz: c094ccfd1860944a60aa8090dd0fec4a7c3cfd33
5
5
  SHA512:
6
- metadata.gz: 2c0a04b753111f99785c95ae61de3d7e79dc95e32d1b7bb15510f833454b34eb02c87d1d0290f14aeb362cf5c619cf8f878b70c970e84a30783c3bebf490977c
7
- data.tar.gz: 3a1e06b66bf9693364b9c9b3a0200fdd96f116ebb183dcf7c315ccf891f3f1d861a1e702f6c9f810dbbf2e93b296421d5918b2f71b7788b6d97f06474c0a2c6f
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 command help.
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 remove foo
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 "run this command from inside the project
54
- hereby the the given resource name
55
- can be given in form of
56
- 'foo(s)', 'foo_bar(s)''"
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
- p created_files
72
+
73
73
  `bundle exec rubocop -a #{created_files.join(' ')}`
74
74
  $stdout.puts "added resource: #{resource}"
75
75
  rescue => e
@@ -14,6 +14,10 @@ module Starter
14
14
  base_file_name.gsub(/.rb$/, '_spec.rb')
15
15
  end
16
16
 
17
+ def mount_point
18
+ " mount Endpoints::#{klass_name}\n"
19
+ end
20
+
17
21
  def api_base_file_name
18
22
  File.join(Dir.getwd, 'api', 'base.rb')
19
23
  end
@@ -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
- add_moint_point
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
- File.open(send(new_file_name), 'w+') { |file| file.write(send(new_file.strip_heredoc)) }
87
+ write_file(send(new_file_name), send(new_file.strip_heredoc))
71
88
  end
72
89
 
73
- def should_raise?(file)
74
- raise StandardError, '… resource exists' if File.exist?(file) && !force
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
- def add_moint_point
78
- file = File.read(api_base_file_name)
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 + " mount Endpoints::#{klass_name}\n"
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
- def endpoint_set
86
- crud_set = singular? ? singular_one : crud
87
- return crud_set if set.blank?
105
+ # … removing
106
+ def remove_from_base(file)
107
+ file.sub!(mount_point, '')
108
+ end
88
109
 
89
- crud_set.each_with_object([]) { |x, memo| set.map { |y| memo << x if x.to_s.start_with?(y) } }
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)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Starter
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
  end
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.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-06 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli