about_yml 0.0.5 → 0.0.6
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/lib/about_yml/about.rb +2 -2
- data/lib/about_yml/data_faker.rb +77 -0
- data/lib/about_yml/template_generator.rb +4 -3
- data/lib/about_yml/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5bed41d12e9955fe24050b2408d21b9eac408af4
|
|
4
|
+
data.tar.gz: fc02acb545c06d36a03f96d144506ae475779b78
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 239b7860d4051f4c01bc46885f3f3a9621252d925c8b9be3044defc3655b9e0e68504f7731706a5f828c05de148d29fd12ca465aeee203a5a9b035dce5e46b19
|
|
7
|
+
data.tar.gz: 4db01b2225d983f7425ec7e6c8526b50affc6fc0d53257eeb4b1fc4649ce1fb40258634cfa491d39cc3c201d0833a222a8ade9095369d4d5da73d97a1d7c75ac
|
data/lib/about_yml/about.rb
CHANGED
|
@@ -25,7 +25,7 @@ module AboutYml
|
|
|
25
25
|
'public' => {},
|
|
26
26
|
'private' => {},
|
|
27
27
|
'missing' => [],
|
|
28
|
-
'errors' =>
|
|
28
|
+
'errors' => {},
|
|
29
29
|
}
|
|
30
30
|
repos.each { |repo| collect_repository_data repo, client, result }
|
|
31
31
|
result
|
|
@@ -39,7 +39,7 @@ module AboutYml
|
|
|
39
39
|
def self.write_error(err, repo, result)
|
|
40
40
|
$stderr.puts('Error while parsing .about.yml for ' \
|
|
41
41
|
"#{repo.full_name}:\n #{err}")
|
|
42
|
-
result['errors']
|
|
42
|
+
result['errors'][repo.full_name] = err.message
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def self.add_github_metadata(result, repo)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @author Alison Rowland (alison.rowland@gsa.gov)
|
|
2
|
+
|
|
3
|
+
require_relative 'about'
|
|
4
|
+
require 'safe_yaml'
|
|
5
|
+
require 'random_data'
|
|
6
|
+
|
|
7
|
+
module AboutYml
|
|
8
|
+
class DataFaker
|
|
9
|
+
attr_reader :template_data
|
|
10
|
+
|
|
11
|
+
TYPE_MAP = {
|
|
12
|
+
'string' => lambda { Random.alphanumeric },
|
|
13
|
+
'boolean' => lambda { Random.boolean },
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@generator = AboutYml::TemplateGenerator.new
|
|
18
|
+
template = @generator.generate
|
|
19
|
+
@template_data = YAML.load template
|
|
20
|
+
|
|
21
|
+
# load up the JSON schema to fill in appropriate values
|
|
22
|
+
schema = AboutYml::AboutFile.schema
|
|
23
|
+
|
|
24
|
+
@template_data.collect do |k, _|
|
|
25
|
+
@template_data[k] = fill_data schema['properties'][k]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# populate the template with random values according to their type
|
|
30
|
+
# in the schema
|
|
31
|
+
def fill_data(props)
|
|
32
|
+
return unless props.key? 'type'
|
|
33
|
+
type = props['type']
|
|
34
|
+
|
|
35
|
+
return props['enum'].rand if props.key? 'enum'
|
|
36
|
+
return fill_array props if type == 'array'
|
|
37
|
+
return fill_object props if type == 'object'
|
|
38
|
+
|
|
39
|
+
TYPE_MAP[type].call if TYPE_MAP[type]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def fill_array(props)
|
|
43
|
+
subtype = props['items']['type']
|
|
44
|
+
|
|
45
|
+
3.times.collect do
|
|
46
|
+
if TYPE_MAP[subtype]
|
|
47
|
+
TYPE_MAP[subtype].call
|
|
48
|
+
else
|
|
49
|
+
subprops = @generator.definition_properties props['items']['$ref']
|
|
50
|
+
fill_new_object subprops
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def fill_object(props)
|
|
56
|
+
if props.key? 'items'
|
|
57
|
+
return fill_data @generator.definition_properties props['items']['$ref']
|
|
58
|
+
elsif props.key? 'patternProperties'
|
|
59
|
+
# this is hacky, but will work unless the "licenses" patternProperties
|
|
60
|
+
# are changed to include more than one pattern
|
|
61
|
+
_, v = props['patternProperties'].shift
|
|
62
|
+
subprops = @generator.definition_properties v['$ref']
|
|
63
|
+
|
|
64
|
+
# the patternProperties works by regex matching on the keys of the
|
|
65
|
+
# sub-object, # so we need to create another level of nesting with
|
|
66
|
+
# a random key
|
|
67
|
+
return { Random.alphanumeric => fill_new_object(subprops) }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def fill_new_object(props)
|
|
72
|
+
new_obj = {}
|
|
73
|
+
props.map { |k, _| new_obj[k] = fill_data props[k] }
|
|
74
|
+
new_obj
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -18,6 +18,10 @@ module AboutYml
|
|
|
18
18
|
"---\n# #{schema['description']}\n#\n#{props.join "\n\n"}"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def definition_properties(item_ref)
|
|
22
|
+
schema['definitions'][item_ref.split('/').last]['properties']
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
private
|
|
22
26
|
|
|
23
27
|
def generate_item(name, definition)
|
|
@@ -60,8 +64,5 @@ module AboutYml
|
|
|
60
64
|
"\n# Items by property name pattern:#{property_descs}"
|
|
61
65
|
end
|
|
62
66
|
|
|
63
|
-
def definition_properties(item_ref)
|
|
64
|
-
schema['definitions'][item_ref.split('/').last]['properties']
|
|
65
|
-
end
|
|
66
67
|
end
|
|
67
68
|
end
|
data/lib/about_yml/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: about_yml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Bland
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2015-11-
|
|
12
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: safe_yaml
|
|
@@ -161,6 +161,7 @@ files:
|
|
|
161
161
|
- bin/github_org_descriptions
|
|
162
162
|
- lib/about_yml.rb
|
|
163
163
|
- lib/about_yml/about.rb
|
|
164
|
+
- lib/about_yml/data_faker.rb
|
|
164
165
|
- lib/about_yml/schema.json
|
|
165
166
|
- lib/about_yml/template_generator.rb
|
|
166
167
|
- lib/about_yml/version.rb
|