nidyx 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/bin/nidyx +24 -26
- data/lib/nidyx/common.rb +8 -2
- data/lib/nidyx/generator.rb +7 -3
- data/lib/nidyx/parser.rb +2 -3
- data/lib/nidyx/version.rb +1 -1
- data/templates/objc/interface.mustache +0 -2
- data/test/nidyx/test_common.rb +1 -0
- data/test/nidyx/test_comparison.rb +1 -1
- data/test/nidyx/test_parser.rb +4 -3
- 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: 8433c258d171e3151329b3623a8fb03ee27cd9a6
|
4
|
+
data.tar.gz: 69d7d5702a72d1123c2bf0659e82c6d517714598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c5d42a4d48c2b1a4b2a45b6e5b99eb27f4a04bed8a25de6b97ca2c102651cf3e11d037260ac105471d46eb5a4a78973685e837d97d2b5107ee412fc6c613275
|
7
|
+
data.tar.gz: 8fed850402a9f1480479aef191a0e45c66bd95515c1606ea5d4adef2a1e2f8a5ef95eb55d848692ca7dd2ea6023efd4646e21d9819e5d4343f3327448eb48f7e
|
data/README.md
CHANGED
@@ -15,14 +15,16 @@ $ gem install nidyx
|
|
15
15
|
|
16
16
|
```
|
17
17
|
usage: nidyx [-h] [--version]
|
18
|
-
nidyx <schema> <class-prefix>
|
19
|
-
[-
|
18
|
+
nidyx <schema> <class-prefix>
|
19
|
+
[-n] [-a author] [-c company] [-p project] [-o directory]
|
20
|
+
[--json-model] # objc specific
|
20
21
|
|
21
22
|
-a, --author AUTHOR Author's name
|
22
23
|
-c, --company COMPANY Company's name
|
23
24
|
-p, --project PROJECT Project's name
|
24
|
-
-
|
25
|
+
-o, --output DIRECTORY Output models to a specific directory
|
25
26
|
-n, --no-comments Generate without header comments
|
27
|
+
--json-model Generate with JSONModel support
|
26
28
|
-h, --help Print usage information
|
27
29
|
--version Print version
|
28
30
|
|
@@ -39,13 +41,12 @@ current directory:
|
|
39
41
|
|
40
42
|
Specify an ouput directory:
|
41
43
|
|
42
|
-
$ nidyx example.json.schema ClassPrefix /path/to/output/directory
|
44
|
+
$ nidyx example.json.schema ClassPrefix -o /path/to/output/directory
|
43
45
|
|
44
|
-
Generate models with JSONModel support and
|
45
|
-
|
46
|
-
$ nidyx example.json.schema ClassPrefix /path/to/output/directory \
|
47
|
-
-j -a "Your Name" -c "Company Name" -p "Project Name"
|
46
|
+
Generate models with JSONModel support and optional documentation:
|
48
47
|
|
48
|
+
$ nidyx example.json.schema ClassPrefix -o /path/to/output/directory \
|
49
|
+
--json-model -a "Your Name" -c "Company Name" -p "Project Name"
|
49
50
|
```
|
50
51
|
|
51
52
|
## Features
|
data/bin/nidyx
CHANGED
@@ -11,8 +11,8 @@ require "nidyx/generator"
|
|
11
11
|
|
12
12
|
BANNER = <<END
|
13
13
|
usage: nidyx [-h] [--version]
|
14
|
-
nidyx <schema>
|
15
|
-
[-
|
14
|
+
nidyx <schema> [-n] [-a author] [-c company] [-p project]
|
15
|
+
[-o directory] [-x prefix]
|
16
16
|
[--json-model] # objc specific
|
17
17
|
|
18
18
|
END
|
@@ -25,19 +25,17 @@ models with JSONModel support.
|
|
25
25
|
Examples
|
26
26
|
========
|
27
27
|
|
28
|
-
|
29
|
-
current directory:
|
28
|
+
Generate models for a given schema.
|
30
29
|
|
31
|
-
$ nidyx example.json.schema
|
30
|
+
$ nidyx example.json.schema
|
32
31
|
|
33
|
-
Specify an ouput directory:
|
32
|
+
Specify an ouput directory and a class prefix:
|
34
33
|
|
35
|
-
$ nidyx example.json.schema ClassPrefix /path/to/output/directory
|
34
|
+
$ nidyx example.json.schema -x ClassPrefix -o /path/to/output/directory
|
36
35
|
|
37
|
-
Generate
|
36
|
+
Generate with JSONModel support and optional documentation:
|
38
37
|
|
39
|
-
$ nidyx example.json.schema
|
40
|
-
-j -a "Your Name" -c "Company Name" -p "Project Name"
|
38
|
+
$ nidyx example.json.schema --json-model -a "Your Name" -p "Project Name"
|
41
39
|
|
42
40
|
END
|
43
41
|
|
@@ -58,24 +56,27 @@ opts = OptionParser.new do |o|
|
|
58
56
|
o.banner = BANNER
|
59
57
|
|
60
58
|
# general generation options
|
61
|
-
o.on("-a", "--author AUTHOR", "Author's name") do |
|
62
|
-
options[:author] =
|
59
|
+
o.on("-a", "--author AUTHOR", "Author's name") do |author|
|
60
|
+
options[:author] = author
|
63
61
|
end
|
64
|
-
|
65
|
-
|
66
|
-
options[:company] = c
|
62
|
+
o.on("-c", "--company COMPANY", "Company's name") do |company|
|
63
|
+
options[:company] = company
|
67
64
|
end
|
68
|
-
|
69
|
-
|
70
|
-
options[:project] = p
|
65
|
+
o.on("-p", "--project PROJECT", "Project's name") do |project|
|
66
|
+
options[:project] = project
|
71
67
|
end
|
72
|
-
|
73
|
-
|
68
|
+
o.on("-o", "--output DIRECTORY", "Output models to a specific directory") do |output_directory|
|
69
|
+
options[:output_directory] = output_directory
|
70
|
+
end
|
71
|
+
o.on("-x", "--class-prefix PREFIX", "Add a prefix to generated model names") do |prefix|
|
72
|
+
options[:class_prefix] = prefix
|
73
|
+
end
|
74
|
+
o.on("-n", "--no-comments", "Generate without header comments") do
|
74
75
|
options[:comments] = false
|
75
76
|
end
|
76
77
|
|
77
78
|
# objc generation options
|
78
|
-
o.on("--json-model", "Generate with JSONModel support") do
|
79
|
+
o.on("--json-model", "Generate with JSONModel support") do
|
79
80
|
options[:objc][:json_model] = true
|
80
81
|
end
|
81
82
|
|
@@ -84,7 +85,6 @@ opts = OptionParser.new do |o|
|
|
84
85
|
puts o
|
85
86
|
exit
|
86
87
|
end
|
87
|
-
|
88
88
|
o.on("--version", "Print version") do
|
89
89
|
puts Nidyx::VERSION
|
90
90
|
exit
|
@@ -101,16 +101,14 @@ rescue OptionParser::InvalidOption => e
|
|
101
101
|
exit 1
|
102
102
|
end
|
103
103
|
|
104
|
-
if ARGV.size <
|
104
|
+
if ARGV.size < 1
|
105
105
|
puts "Too few arguments." unless ARGV.empty?
|
106
106
|
puts opts
|
107
107
|
exit 1
|
108
108
|
end
|
109
109
|
|
110
|
-
options[:output_path] = ARGV[2]
|
111
|
-
|
112
110
|
###
|
113
111
|
# run
|
114
112
|
###
|
115
113
|
|
116
|
-
Nidyx::Generator.run(ARGV[0],
|
114
|
+
Nidyx::Generator.run(ARGV[0], options)
|
data/lib/nidyx/common.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require "nidyx/parse_constants"
|
2
|
+
|
3
|
+
include Nidyx::ParseConstants
|
4
|
+
|
1
5
|
module Nidyx
|
2
6
|
module Common
|
3
7
|
class NoObjectAtPathError < StandardError; end
|
@@ -6,10 +10,12 @@ module Nidyx
|
|
6
10
|
IGNORED_KEYS = "properties", "definitions"
|
7
11
|
|
8
12
|
def class_name(prefix, key)
|
9
|
-
if key
|
13
|
+
if key && prefix
|
10
14
|
prefix + key.camelize + CLASS_SUFFIX
|
11
|
-
|
15
|
+
elsif prefix
|
12
16
|
prefix + CLASS_SUFFIX
|
17
|
+
else
|
18
|
+
CLASS_SUFFIX
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
data/lib/nidyx/generator.rb
CHANGED
@@ -7,11 +7,15 @@ module Nidyx
|
|
7
7
|
module Generator
|
8
8
|
extend self
|
9
9
|
|
10
|
-
|
10
|
+
# The Nidyx model generator. Called by the Nidyx CLI. Parses the input
|
11
|
+
# schema, creates models and writes them to the output directory.
|
12
|
+
# @param schema_path [String] Path to the schema to generate models with.
|
13
|
+
# @param options [Hash] Model generation options hash.
|
14
|
+
def run(schema_path, options)
|
11
15
|
schema = Nidyx::Reader.read(schema_path)
|
12
|
-
raw_models = Nidyx::Parser.parse(
|
16
|
+
raw_models = Nidyx::Parser.parse(schema, options)
|
13
17
|
models = Nidyx::Mapper.map(raw_models, options)
|
14
|
-
Nidyx::Output.write(models, options[:
|
18
|
+
Nidyx::Output.write(models, options[:output_directory])
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/nidyx/parser.rb
CHANGED
@@ -13,13 +13,12 @@ module Nidyx
|
|
13
13
|
|
14
14
|
class UnsupportedSchemaError < StandardError; end
|
15
15
|
|
16
|
-
# @param model_prefix [String] the prefix for model names
|
17
16
|
# @param schema [Hash] JSON Schema
|
18
17
|
# @param options [Hash] global application options
|
19
18
|
# @return [Hash] a Hash of ModelData objects
|
20
|
-
def parse(
|
19
|
+
def parse(schema, options)
|
21
20
|
# setup parser
|
22
|
-
@class_prefix =
|
21
|
+
@class_prefix = options[:class_prefix]
|
23
22
|
@options = options
|
24
23
|
@schema = schema
|
25
24
|
@models = {}
|
data/lib/nidyx/version.rb
CHANGED
@@ -6,12 +6,10 @@
|
|
6
6
|
|
7
7
|
{{/json_model?}}
|
8
8
|
@interface {{name}}{{#json_model?}} : JSONModel{{/json_model?}}
|
9
|
-
|
10
9
|
{{#properties}}
|
11
10
|
{{#desc}}
|
12
11
|
// {{{desc}}}
|
13
12
|
{{/desc}}
|
14
13
|
@property ({{attributes}}{{getter_override}}) {{type_name}}{{#json_model?}}{{#has_protocols?}}<{{protocols_string}}>{{/has_protocols?}}{{/json_model?}} {{#is_obj?}}*{{/is_obj?}}{{name}};
|
15
14
|
{{/properties}}
|
16
|
-
|
17
15
|
@end
|
data/test/nidyx/test_common.rb
CHANGED
@@ -9,6 +9,7 @@ class TestCommon < Minitest::Test
|
|
9
9
|
assert_equal("DKResponseModel", class_name("DK", "response"))
|
10
10
|
assert_equal("DKModel", class_name("DK", nil))
|
11
11
|
assert_equal("DKLargeButtonModel", class_name("DK", "large_button"))
|
12
|
+
assert_equal("Model", class_name(nil, nil))
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_class_name_from_path
|
@@ -40,7 +40,7 @@ class TestComparison < Minitest::Test
|
|
40
40
|
def run_generate(example_name)
|
41
41
|
cmd = "bundle exec nidyx " <<
|
42
42
|
example_schema_path(example_name) <<
|
43
|
-
" #{PREFIX} #{TMP_PATH} -n --json-model"
|
43
|
+
" -x #{PREFIX} -o #{TMP_PATH} -n --json-model"
|
44
44
|
|
45
45
|
assert(false) unless system(cmd)
|
46
46
|
end
|
data/test/nidyx/test_parser.rb
CHANGED
@@ -446,8 +446,9 @@ class TestParser < Minitest::Test
|
|
446
446
|
|
447
447
|
private
|
448
448
|
|
449
|
-
|
450
|
-
|
449
|
+
OPTIONS = {
|
450
|
+
:class_prefix => "TS"
|
451
|
+
}
|
451
452
|
|
452
453
|
def assert_deps(expected, model)
|
453
454
|
actual = model.dependencies
|
@@ -455,6 +456,6 @@ class TestParser < Minitest::Test
|
|
455
456
|
end
|
456
457
|
|
457
458
|
def parse(schema)
|
458
|
-
Nidyx::Parser.parse(
|
459
|
+
Nidyx::Parser.parse(schema, OPTIONS)
|
459
460
|
end
|
460
461
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nidyx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Knadler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mustache
|