spectifly 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spectifly/entity.rb +15 -8
- data/lib/spectifly/version.rb +1 -1
- data/lib/tasks/spectifly.rake +26 -3
- data/spec/fixtures/presenters/{masterless_group.entity → masterless_group/group.entity} +0 -0
- data/spec/fixtures/presenters/{positionless_individual.entity → positionless_individual/individual.entity} +0 -0
- data/spec/spectifly/entity_spec.rb +13 -7
- data/spec/spectifly/json/builder_spec.rb +3 -3
- data/spec/spectifly/xsd/builder_spec.rb +3 -3
- metadata +12 -7
data/lib/spectifly/entity.rb
CHANGED
@@ -20,13 +20,20 @@ module Spectifly
|
|
20
20
|
entities[entity.name] = entity
|
21
21
|
end
|
22
22
|
if presenter_path
|
23
|
-
presenters_glob = File.join(presenter_path, '
|
24
|
-
Dir[presenters_glob].each do |
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
presenters_glob = File.join(presenter_path, '*')
|
24
|
+
Dir[presenters_glob].each do |presenter_list_path|
|
25
|
+
if File.directory? presenter_list_path
|
26
|
+
presenter_name = presenter_list_path.sub(/^#{presenter_path}\//, '')
|
27
|
+
entities[presenter_name] = {}
|
28
|
+
entities_glob = File.join(presenter_list_path, '*.entity')
|
29
|
+
Dir[entities_glob].each do |path|
|
30
|
+
path = File.expand_path(path)
|
31
|
+
presenter = Spectifly::Entity.parse(path)
|
32
|
+
base_entity = entities[Spectifly::Support.tokenize(presenter.root)]
|
33
|
+
entity = base_entity.present_as(presenter)
|
34
|
+
entities[presenter_name][entity.name] = entity
|
35
|
+
end
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
32
39
|
entities
|
@@ -103,4 +110,4 @@ module Spectifly
|
|
103
110
|
merged_entity
|
104
111
|
end
|
105
112
|
end
|
106
|
-
end
|
113
|
+
end
|
data/lib/spectifly/version.rb
CHANGED
data/lib/tasks/spectifly.rake
CHANGED
@@ -1,11 +1,25 @@
|
|
1
|
+
require 'spectifly/xsd'
|
2
|
+
|
1
3
|
namespace :spectifly do
|
2
4
|
namespace :xsd do
|
5
|
+
def write_entity(entity, path)
|
6
|
+
File.open(File.join(path, "#{entity.name}.xsd"), 'w') do |f|
|
7
|
+
f.write Spectifly::Xsd::Builder.new(entity).build
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
Spectifly::Task.new('generate_from_entities', [:destination_path]) do |spectifly, args|
|
4
12
|
options = File.exist?(spectifly.presenter_path) ? { :presenter_path => spectifly.presenter_path } : {}
|
5
13
|
|
6
14
|
Spectifly::Entity.from_directory(spectifly.entity_path, options).each do |name, entity|
|
7
|
-
|
8
|
-
|
15
|
+
if entity.is_a? Spectifly::Entity
|
16
|
+
write_entity(entity, args[:destination_path])
|
17
|
+
else
|
18
|
+
presenter_path = File.join(args[:destination_path], name)
|
19
|
+
FileUtils.mkdir_p presenter_path unless File.exist? presenter_path
|
20
|
+
entity.each do |presenter_entity_name, presenter_entity|
|
21
|
+
write_entity(presenter_entity, presenter_path)
|
22
|
+
end
|
9
23
|
end
|
10
24
|
end
|
11
25
|
end
|
@@ -16,7 +30,16 @@ namespace :spectifly do
|
|
16
30
|
end
|
17
31
|
end
|
18
32
|
|
33
|
+
Spectifly::Task.new('ensure_presenter_validity', [:destination_path]) do |spectifly, args|
|
34
|
+
# just copy all the xsds over into each presenter directory, for easy zipping and whatnot
|
35
|
+
schema = Dir.glob(File.join(args[:destination_path], '*.xsd'))
|
36
|
+
directories = (Dir.glob(File.join(args[:destination_path], "*")) - schema)
|
37
|
+
directories.each do |path|
|
38
|
+
FileUtils.cp schema, path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
19
42
|
desc 'Generate all XSDs for the configured entity directory, including extended type definitions'
|
20
|
-
task :generate_all, [:destination_path] => [:generate_from_entities, :generate_extended_types]
|
43
|
+
task :generate_all, [:destination_path] => [:generate_from_entities, :generate_extended_types, :ensure_presenter_validity]
|
21
44
|
end
|
22
45
|
end
|
File without changes
|
File without changes
|
@@ -17,9 +17,15 @@ describe Spectifly::Entity do
|
|
17
17
|
entities = Spectifly::Entity.from_directory(
|
18
18
|
fixture_path, :presenter_path => base_presenter_path
|
19
19
|
)
|
20
|
+
|
20
21
|
entities.keys.should =~ ['individual', 'group', 'positionless_individual', 'masterless_group']
|
21
|
-
entities.
|
22
|
-
entities.values.map(&:name).should
|
22
|
+
entities['positionless_individual'].keys.should == ['individual']
|
23
|
+
entities['positionless_individual'].values.map(&:name).should == ['individual']
|
24
|
+
entities['masterless_group'].keys.should == ['group']
|
25
|
+
entities['masterless_group'].values.map(&:name).should == ['group']
|
26
|
+
['positionless_individual', 'masterless_group'].each do |presenter|
|
27
|
+
entities[presenter].values.map(&:class).uniq.should == [Spectifly::Entity]
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
@@ -59,17 +65,17 @@ describe Spectifly::Entity do
|
|
59
65
|
describe '#name' do
|
60
66
|
before :each do
|
61
67
|
@presenter_entity = Spectifly::Entity.parse(
|
62
|
-
fixture_path('presenters/positionless_individual')
|
68
|
+
fixture_path('presenters/positionless_individual/individual.entity')
|
63
69
|
)
|
64
70
|
end
|
65
71
|
|
66
72
|
it 'returns name from entity file' do
|
67
73
|
@entity.name.should == 'individual'
|
68
|
-
@presenter_entity.name.should == '
|
74
|
+
@presenter_entity.name.should == 'individual'
|
69
75
|
end
|
70
76
|
|
71
77
|
it 'returns presenter name when presented' do
|
72
|
-
@entity.present_as(@presenter_entity).name.should == '
|
78
|
+
@entity.present_as(@presenter_entity).name.should == 'individual'
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
@@ -80,7 +86,7 @@ describe Spectifly::Entity do
|
|
80
86
|
|
81
87
|
it 'returns presenter if presented' do
|
82
88
|
@presenter_entity = Spectifly::Entity.parse(
|
83
|
-
fixture_path('presenters/positionless_individual')
|
89
|
+
fixture_path('presenters/positionless_individual/individual.entity')
|
84
90
|
)
|
85
91
|
@entity.present_as(@presenter_entity).presented_as.should == @presenter_entity
|
86
92
|
end
|
@@ -129,7 +135,7 @@ describe Spectifly::Entity do
|
|
129
135
|
|
130
136
|
describe '#present_as' do
|
131
137
|
before :each do
|
132
|
-
@presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual'))
|
138
|
+
@presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual/individual'))
|
133
139
|
end
|
134
140
|
|
135
141
|
it 'raises exception if presenter entity has different root' do
|
@@ -21,7 +21,7 @@ describe Spectifly::Json::Builder do
|
|
21
21
|
describe '#present_as' do
|
22
22
|
it 'filters entity through presenter, and returns self' do
|
23
23
|
entity = Spectifly::Entity.parse(fixture_path('individual'))
|
24
|
-
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual'))
|
24
|
+
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual/individual'))
|
25
25
|
json_path = expectation_path('presented/positionless_individual', 'json')
|
26
26
|
builder = described_class.new(entity)
|
27
27
|
builder.present_as(presenter_entity).should == builder
|
@@ -31,7 +31,7 @@ describe Spectifly::Json::Builder do
|
|
31
31
|
|
32
32
|
it 'works with overriding relationships' do
|
33
33
|
entity = Spectifly::Entity.parse(fixture_path('group'))
|
34
|
-
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/masterless_group'))
|
34
|
+
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/masterless_group/group'))
|
35
35
|
json_path = expectation_path('presented/masterless_group', 'json')
|
36
36
|
builder = described_class.new(entity)
|
37
37
|
builder.present_as(presenter_entity).should == builder
|
@@ -39,4 +39,4 @@ describe Spectifly::Json::Builder do
|
|
39
39
|
JSON.pretty_generate(hash).should == File.read(json_path)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
@@ -30,7 +30,7 @@ describe Spectifly::Xsd::Builder do
|
|
30
30
|
describe '#present_as' do
|
31
31
|
it 'filters entity through presenter, and returns self' do
|
32
32
|
entity = Spectifly::Entity.parse(fixture_path('individual'))
|
33
|
-
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual'))
|
33
|
+
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual/individual'))
|
34
34
|
xsd_path = expectation_path('presented/positionless_individual', 'xsd')
|
35
35
|
builder = Spectifly::Xsd::Builder.new(entity)
|
36
36
|
builder.present_as(presenter_entity).should == builder
|
@@ -40,7 +40,7 @@ describe Spectifly::Xsd::Builder do
|
|
40
40
|
|
41
41
|
it 'works with presented relationship-having entities' do
|
42
42
|
entity = Spectifly::Entity.parse(fixture_path('group'))
|
43
|
-
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/masterless_group'))
|
43
|
+
presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/masterless_group/group'))
|
44
44
|
xsd_path = expectation_path('presented/masterless_group', 'xsd')
|
45
45
|
builder = Spectifly::Xsd::Builder.new(entity)
|
46
46
|
builder.present_as(presenter_entity).should == builder
|
@@ -48,4 +48,4 @@ describe Spectifly::Xsd::Builder do
|
|
48
48
|
xsd.should == File.read(xsd_path)
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectifly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -178,8 +178,8 @@ files:
|
|
178
178
|
- spec/fixtures/individual.entity
|
179
179
|
- spec/fixtures/invalid/multiple_root.entity
|
180
180
|
- spec/fixtures/invalid/no_fields.entity
|
181
|
-
- spec/fixtures/presenters/masterless_group.entity
|
182
|
-
- spec/fixtures/presenters/positionless_individual.entity
|
181
|
+
- spec/fixtures/presenters/masterless_group/group.entity
|
182
|
+
- spec/fixtures/presenters/positionless_individual/individual.entity
|
183
183
|
- spec/spec_helper.rb
|
184
184
|
- spec/spectifly/base/builder_spec.rb
|
185
185
|
- spec/spectifly/base/entity_node_spec.rb
|
@@ -207,12 +207,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
207
|
- - ! '>='
|
208
208
|
- !ruby/object:Gem::Version
|
209
209
|
version: '0'
|
210
|
+
segments:
|
211
|
+
- 0
|
212
|
+
hash: -3903166964616575918
|
210
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
214
|
none: false
|
212
215
|
requirements:
|
213
216
|
- - ! '>='
|
214
217
|
- !ruby/object:Gem::Version
|
215
218
|
version: '0'
|
219
|
+
segments:
|
220
|
+
- 0
|
221
|
+
hash: -3903166964616575918
|
216
222
|
requirements: []
|
217
223
|
rubyforge_project:
|
218
224
|
rubygems_version: 1.8.23
|
@@ -233,8 +239,8 @@ test_files:
|
|
233
239
|
- spec/fixtures/individual.entity
|
234
240
|
- spec/fixtures/invalid/multiple_root.entity
|
235
241
|
- spec/fixtures/invalid/no_fields.entity
|
236
|
-
- spec/fixtures/presenters/masterless_group.entity
|
237
|
-
- spec/fixtures/presenters/positionless_individual.entity
|
242
|
+
- spec/fixtures/presenters/masterless_group/group.entity
|
243
|
+
- spec/fixtures/presenters/positionless_individual/individual.entity
|
238
244
|
- spec/spec_helper.rb
|
239
245
|
- spec/spectifly/base/builder_spec.rb
|
240
246
|
- spec/spectifly/base/entity_node_spec.rb
|
@@ -248,4 +254,3 @@ test_files:
|
|
248
254
|
- spec/spectifly/xsd/field_spec.rb
|
249
255
|
- spec/spectifly/xsd/types_spec.rb
|
250
256
|
- spec/support/path_helper.rb
|
251
|
-
has_rdoc:
|