textualize 0.3.0 → 0.4.0

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: 1002740ce8312d3042b58cacdc6953f98e7ac271
4
- data.tar.gz: 8d120ce966239388fc10f6ffa706420aba5dab13
3
+ metadata.gz: 40b4378d74aad501c4231d65040a3891d7e69020
4
+ data.tar.gz: c4a2ed367f25aa1ec7a559c00d52316dda47a295
5
5
  SHA512:
6
- metadata.gz: a9c1effc970b2bd6773b2acac676f8b17434677660c90921043717fb0ec559d0b9a5e2f6b2d7eaed076eaf691d0e3085b49b3f01f199ca49f543a5fc2c98f8c0
7
- data.tar.gz: 5d7a8bff9d9bba57bbdb5c8bf41ff251a689701ac20ae27055fdebf40c8be9ec87320753b946d970c2c706c057618937fe3eb80cb2d1bc666d67ecdd003141f2
6
+ metadata.gz: 0a00aea0eeb0e2cf4f398e1d0dac0481d08f38c819326b2ea0606d4aaf4f40ce60cb7d27aa06a4e52cbf5dc8d2e2fe828df19f42aedda8bda023bef58bd264a3
7
+ data.tar.gz: 8cc879704f2a2841682b6963fa4cb5c80545aa0e3a53088f3d5dd2b0a7db6829fe80965fb438aa4ad9dcef3c98fe96726ac4ce89a1e36e02990a35a8a4126b0e
@@ -26,6 +26,12 @@ module Textualize
26
26
  method_hash = Hashie::Mash.new
27
27
 
28
28
  method_hash.verb = method.fetch('method')
29
+ method_hash.url = base_path + relative_path
30
+ method_hash.relative_path = relative_path
31
+ method_hash.type = resource.fetch('type').keys.first
32
+ method_hash.name = relative_path.split('/').last.gsub(
33
+ /{|}|_id/, ''
34
+ )
29
35
 
30
36
  if method_hash.verb == 'post'
31
37
  method_hash.schema = method.fetch('body').
@@ -33,14 +39,11 @@ module Textualize
33
39
  fetch('schema')
34
40
  end
35
41
 
36
- method_hash.url = base_path + relative_path
37
- method_hash.relative_path = relative_path
38
- method_hash.type = resource.fetch('type').keys.first
39
- method_hash.secured_by = method.fetch('securedBy').first.
40
- fetch('oauth_2_0').fetch('scopes')
41
- method_hash.name = relative_path.split('/').last.gsub(
42
- /{|}|_id/, ''
43
- )
42
+ if method.has_key?('securedBy')
43
+ method_hash.secured_by = method.fetch('securedBy').first.
44
+ fetch('oauth_2_0').fetch('scopes')
45
+ end
46
+
44
47
  method_hash.merge!(transformed_response(method))
45
48
  end
46
49
 
@@ -1,13 +1,16 @@
1
1
  module Textualize
2
2
  class RouteHashes
3
3
  class << self
4
- def hashes
4
+ def filenames_and_hashes
5
5
  fail 'run gulp first' if raml_json_files.empty?
6
6
 
7
- raml_json_files.flat_map do |json_file|
7
+ raml_json_files.map do |json_file|
8
8
  json = JSON.parse(File.read(json_file))
9
9
 
10
- RouteHashCreator.new(json).create_route_hashes
10
+ [
11
+ File.basename(json_file, '.*'),
12
+ RouteHashCreator.new(json).create_route_hashes
13
+ ]
11
14
  end
12
15
  end
13
16
 
@@ -8,32 +8,34 @@ module Textualize
8
8
  'Creates an angular 1.x module based off ngMockE2E that stubs a backend'
9
9
  )
10
10
 
11
- def create_angular_module
12
- create_basic_http_backend_file
11
+ def create_backend_angular_modules
12
+ RouteHashes.filenames_and_hashes.each do |(filename, hashes)|
13
+ puts hashes
14
+ puts filename
13
15
 
14
- append_uglified_hashes
15
- end
16
+ FileUtils.mkdir_p("dist/#{filename}/angular/backend")
16
17
 
17
- private
18
+ File.open(dist_file(filename), 'w') do |file|
19
+ file.write(
20
+ File.read("#{template_directory}/module.js")
21
+ )
22
+ end
18
23
 
19
- def create_basic_http_backend_file
20
- File.open(dist_file, 'w') do |file|
21
- file.write(
22
- File.read("#{template_directory}/module.js")
23
- )
24
+ hashes.each do |route_hash|
25
+ modified_hash = replace_sample_id_with_1(route_hash)
26
+ File.open(dist_file(filename), 'a') do |file|
27
+ file.write(
28
+ http_backend_template(modified_hash)
29
+ )
30
+ end
31
+ end
24
32
  end
25
33
  end
26
34
 
27
- def dist_file
28
- FileUtils.mkdir_p('dist/angular/backend')
29
-
30
- 'dist/angular/backend/fake_http_backend.min.js'
31
- end
35
+ private
32
36
 
33
- def http_backend_template(route_hash)
34
- ERB.new(
35
- File.read("#{template_directory}/#{route_hash.verb}.js.erb")
36
- ).result(route_hash.instance_eval { binding })
37
+ def dist_file(filename)
38
+ "dist/#{filename}/angular/backend/fake_http_backend.min.js"
37
39
  end
38
40
 
39
41
  def template_directory
@@ -41,19 +43,16 @@ module Textualize
41
43
  File.expand_path(path)
42
44
  end
43
45
 
44
- def append_uglified_hashes
45
- RouteHashes.hashes.each do |route_hash|
46
- # replace sample ids with 1
47
- modified_hash = route_hash
48
- modified_hash.relative_path.gsub!(/{.*}/, '1')
49
- modified_hash.url.gsub!(/{.*}/, '1')
46
+ def replace_sample_id_with_1(route_hash)
47
+ route_hash.relative_path.gsub!(/{.*}/, '1')
48
+ route_hash.url.gsub!(/{.*}/, '1')
49
+ return route_hash
50
+ end
50
51
 
51
- File.open(dist_file, 'a') do |file|
52
- file.write(
53
- http_backend_template(modified_hash)
54
- )
55
- end
56
- end
52
+ def http_backend_template(route_hash)
53
+ ERB.new(
54
+ File.read("#{template_directory}/#{route_hash.verb}.js.erb")
55
+ ).result(route_hash.instance_eval { binding })
57
56
  end
58
57
  end
59
58
  end
@@ -4,33 +4,31 @@ module Textualize
4
4
  class RequestSpecs < Thor::Group
5
5
  include Thor::Actions
6
6
 
7
- RS_DIRECTORY = 'dist/spec/requests/'
8
-
9
7
  desc(
10
8
  'Creates request specs for an api using airborne, a ruby gem'
11
9
  )
12
10
 
13
11
  def create_airborne_specs
14
- FileUtils.mkdir_p(RS_DIRECTORY)
15
-
16
12
  add_airborne_specs
17
13
  end
18
14
 
19
15
  private
20
16
 
21
17
  def add_airborne_specs
22
- RouteHashes.hashes.each do |route_hash|
18
+ RouteHashes.filenames_and_hashes.each do |(filename, hashes)|
19
+ request_directory = "dist/#{filename}/spec/requests/"
23
20
 
24
- # replace sample ids with interpolated ruby
25
- modified_hash = route_hash
21
+ FileUtils.mkdir_p(request_directory)
26
22
 
27
- modified_hash.relative_path.gsub!(/({|_id)/, '{' => '#{', '_id' => '.id')
28
- modified_hash.url.gsub!(/({|_id)/, '{' => '#{', '_id' => '.id')
23
+ hashes.each do |route_hash|
24
+ modified_hash = replace_ids_with_interpolated_ruby(route_hash)
29
25
 
30
- File.open(
31
- "#{RS_DIRECTORY}#{route_hash.verb}_#{route_hash.name}_spec.rb", 'w'
32
- ) do |file|
33
- file.write(request_spec_template(modified_hash))
26
+ File.open(
27
+ "#{request_directory}#{route_hash.verb}_"\
28
+ "#{route_hash.name}_spec.rb", 'w'
29
+ ) do |file|
30
+ file.write(request_spec_template(modified_hash))
31
+ end
34
32
  end
35
33
  end
36
34
  end
@@ -51,5 +49,12 @@ module Textualize
51
49
  def non_ro_type(route_hash)
52
50
  route_hash.type.gsub(/-ro$/, '')
53
51
  end
52
+
53
+ def replace_ids_with_interpolated_ruby(route_hash)
54
+ modified_hash = route_hash
55
+ modified_hash.relative_path.gsub!(/({|_id)/, '{' => '#{', '_id' => '.id')
56
+ modified_hash.url.gsub!(/({|_id)/, '{' => '#{', '_id' => '.id')
57
+ modified_hash
58
+ end
54
59
  end
55
60
  end
@@ -10,26 +10,28 @@ module Textualize
10
10
  )
11
11
 
12
12
  def create_method_files
13
- RouteHashes.hashes.each do |route_hash|
14
- next unless route_hash.verb == 'get'
15
- next if route_hash.body.empty?
13
+ RouteHashes.filenames_and_hashes.each do |(filename, hashes)|
14
+ FileUtils.mkdir_p("dist/#{filename}/server")
16
15
 
17
- route_directory = "#{dist_dir}#{route_hash.url}"
16
+ hashes.each do |route_hash|
17
+ next unless route_hash.verb == 'get'
18
+ next if route_hash.body.empty?
18
19
 
19
- FileUtils.mkdir_p(route_directory)
20
+ route_directory = "#{dist_dir(filename)}#{route_hash.url}"
20
21
 
21
- File.open("#{route_directory}/#{route_hash.verb}.json", 'w') do |file|
22
- file.write route_hash.body.to_json
22
+ FileUtils.mkdir_p(route_directory)
23
+
24
+ File.open("#{route_directory}/#{route_hash.verb}.json", 'w') do |file|
25
+ file.write route_hash.body.to_json
26
+ end
23
27
  end
24
28
  end
25
29
  end
26
30
 
27
31
  private
28
32
 
29
- def dist_dir
30
- FileUtils.mkdir_p('dist/server')
31
-
32
- 'dist/server'
33
+ def dist_dir(filename)
34
+ "dist/#{filename}/server"
33
35
  end
34
36
  end
35
37
  end
@@ -2,6 +2,9 @@ dependencies:
2
2
  override:
3
3
  - npm install
4
4
  - npm install --global gulp
5
+ - sudo apt-get -y update; sudo apt-get -y install jq
5
6
  test:
6
7
  override:
7
8
  - gulp
9
+ - cat apis/*/samples/*.json | jq '.data'
10
+
@@ -1,3 +1,3 @@
1
1
  module Textualize
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textualize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Q-Centrix Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor