spectifly 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,23 +48,24 @@ Widget:
48
48
 
49
49
  Awesome?:
50
50
  Description: Whether or not the widget is awesome
51
+
51
52
  Related Entities:
52
53
  Belongs To:
53
54
  Manufacturing Plant*:
54
55
  Description: The WidgetCo location that constructed the widget
55
56
  Type: Manufacturing Location
57
+
56
58
  Has Many:
57
59
  Accessories:
58
- Description: Widget Add-ons that augment the widget's
59
- functionality
60
+ Description: Widget Add-ons that augment the widget's functionality
60
61
  Type: Add On
61
62
  ```
62
63
 
63
64
  The root node, `Widget:` above, is required, and there can be only one node at
64
65
  this level.
65
66
 
66
- Directly below the root node, the only valid nodes are `Description` and
67
- `Fields`. The `Description` is a plain language description of the entity. The `Related Entities` node includes associations to other entities, grouped by how the entity is related.
67
+ Directly below the root node, the only valid nodes are `Description` (optional),
68
+ `Fields` (required), and `Related Entities` (optional). The `Description` is a plain language description of the entity. The `Related Entities` node includes associations to other entities, grouped by how the entity is related.
68
69
 
69
70
  ### Fields
70
71
 
@@ -102,22 +103,17 @@ If the `?` shortcut conflicts with the explicit key (e.g. a `Rad?` field with
102
103
 
103
104
  ### Related Entities
104
105
 
105
- `Related Entities`, is a YAML tree that enumerates the entities with which the defined entity are associated. They are grouped by type of relationship and include the name of the association and which type of entity that association links to. Like `Fields`, the `*` special token can be used to mark an entity as required.
106
+ `Related Entities` is a YAML tree that enumerates the entities with which the defined entity is associated. They are grouped by type of relationship and include the name of the association and which type of entity that association links to. Like `Fields`, the `*` special token can be used to mark an association as required. If a plural association (such as has_many or has_and_belongs_to_many) is marked as required, that relationship must have *at least one* member.
106
107
 
107
- * `Belongs To` is fairly straight-forward, i.e. a kitten belongs to a
108
- litter of kittens
108
+ * `Belongs To` is a singular association, where the owner is the other entity (e.g. a kitten belongs to a litter of kittens)
109
109
 
110
- * `Has One` also self-explanatory, i.e. a website user has one (and only
111
- one) profile -- an inverse of `Belongs To`
110
+ * `Has One` is a singular association, where the owner is this entity (e.g. a kitten has one (and only one) nose) -- an inverse of `Belongs To`
112
111
 
113
- * `Has Many` also an inverse of `Belongs To`, but 1 or more
112
+ * `Has Many` is a plural association, where the owner is this entity (e.g. a kitten has many toys) -- also can be an inverse of `Belongs To`
114
113
 
115
- * `Has and Belongs To Many` is a many-to-many relationship between two
116
- entities, such as a dish being made up of many ingredients and an
117
- ingredient being part of many dishes
114
+ * `Has and Belongs To Many` is a many-to-many relationship between two entities, and plural on both sides (e.g. a dish is made up of many ingredients, and an ingredient is a component of many dishes)
118
115
 
119
- Under each of these Association nodes the YAML tree lists entities that relate to
120
- the described entity in that way.
116
+ Under each of these association nodes, the YAML tree lists entities that relate to the described entity in that way.
121
117
 
122
118
  ## Contributing
123
119
 
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
- require 'spectifly/tasks'
3
2
  require 'rspec/core/rake_task'
4
3
  RSpec::Core::RakeTask.new(:spec) do |spec|
5
4
  spec.pattern = FileList['spec/**/*_spec.rb']
6
5
  end
7
6
 
8
- task :default => :spec
7
+ task :default => :spec
@@ -1,8 +1,9 @@
1
1
  module Spectifly
2
2
  class Configuration
3
+ attr_accessor :entity_path
3
4
  def initialize(config = {})
4
- @entity_path = config.fetch(:entity_path)
5
- @presenter_path = config[:presenter_path]
5
+ @entity_path = config.fetch('entity_path')
6
+ @presenter_path = config['presenter_path']
6
7
  end
7
8
 
8
9
  def presenter_path
@@ -1,15 +1,22 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
+ require 'yaml'
4
+ require 'spectifly/configuration'
3
5
 
4
6
  module Spectifly
5
7
  class Task < ::Rake::TaskLib
6
- attr_accessor :config_path
8
+ attr_accessor :configuration
9
+
10
+ def configure!
11
+ config_path = File.join(Rake.original_dir, 'config', 'spectifly.yml')
12
+ config_hash = File.exist?(config_path) ? YAML.load_file(config_path) : {}
13
+ @configuration = Spectifly::Configuration.new(config_hash)
14
+ end
7
15
 
8
16
  def initialize(task_name, *args, &block)
9
- @stuff = 'default stuff'
17
+ configure!
10
18
  task task_name, *args do |task_name, task_args|
11
- block.call(self) if block
12
- puts "This is #{task_name} task with #{config_path}"
19
+ block.call(configuration, task_args) if block
13
20
  end
14
21
  end
15
22
  end
@@ -1,3 +1,3 @@
1
1
  module Spectifly
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,6 +1,22 @@
1
1
  namespace :spectifly do
2
- desc 'Do whatever'
3
- Spectifly::Task.new('whatever') do |sfly|
4
- sfly.config_path = File.join(Rake.original_dir, 'config', 'spectifly.yml')
2
+ namespace :xsd do
3
+ Spectifly::Task.new('generate_from_entities', [:destination_path]) do |spectifly, args|
4
+ options = File.exist?(spectifly.presenter_path) ? { :presenter_path => spectifly.presenter_path } : {}
5
+
6
+ Spectifly::Entity.from_directory(spectifly.entity_path, options).each do |name, entity|
7
+ File.open(File.join(args[:destination_path], "#{name}.xsd"), 'w') do |f|
8
+ f.write Spectifly::Xsd::Builder.new(entity).build
9
+ end
10
+ end
11
+ end
12
+
13
+ Spectifly::Task.new('generate_extended_types', [:destination_path]) do |spectifly, args|
14
+ File.open(File.join(args[:destination_path], "extended.xsd"), 'w') do |f|
15
+ f.write Spectifly::Xsd::Types.build_extended
16
+ end
17
+ end
18
+
19
+ 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]
5
21
  end
6
- end
22
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Spectifly::Configuration do
4
4
  let(:configuration_args) {
5
5
  {
6
- :entity_path => base_fixture_path
6
+ 'entity_path' => base_fixture_path
7
7
  }
8
8
  }
9
9
  describe '.initialize' do
@@ -12,7 +12,7 @@ describe Spectifly::Configuration do
12
12
  end
13
13
 
14
14
  it 'fails if no entity path provided' do
15
- configuration_args.delete(:entity_path)
15
+ configuration_args.delete('entity_path')
16
16
  expect { described_class.new(configuration_args) }.to raise_error
17
17
  end
18
18
  end
@@ -20,14 +20,14 @@ describe Spectifly::Configuration do
20
20
  describe '#presenter_path' do
21
21
  it 'returns configured value if set' do
22
22
  configuration = described_class.new(
23
- configuration_args.merge(:presenter_path => 'goose')
23
+ configuration_args.merge('presenter_path' => 'goose')
24
24
  )
25
25
  configuration.presenter_path.should == 'goose'
26
26
  end
27
27
 
28
28
  it 'returns nil if no presenter path exists at entity path' do
29
29
  configuration = described_class.new(
30
- configuration_args.merge(:entity_path => spec_path)
30
+ configuration_args.merge('entity_path' => spec_path)
31
31
  )
32
32
  configuration.presenter_path.should be_nil
33
33
  end
@@ -39,4 +39,4 @@ describe Spectifly::Configuration do
39
39
  configuration.presenter_path.should == base_presenter_path
40
40
  end
41
41
  end
42
- end
42
+ 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.1
4
+ version: 0.0.2
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-05-17 00:00:00.000000000 Z
12
+ date: 2013-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder