picatrix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e2e397e99116fa0b237db3f59a35ab0c7521f4e
4
+ data.tar.gz: 835f2a685518c5448ad260577949244cf1feca77
5
+ SHA512:
6
+ metadata.gz: 0cbd222ea637fe500cc864a89dcb244e743405d83b31cadbb1e6b891637c50a8a898a83e9f39b5426d514fb955f3d36be5823d89d9087c5b08150a485bf6c9f8
7
+ data.tar.gz: a36dc255cf23bc5305af1edaf7299bd65db0a6a9b4259e138fa1ecbbbf0d322c9d8beff005812a4fdbbcecdf6aca9db81c128d46208961284e9c990396a18e3a
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ .DS_Store
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in picatrix.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,130 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ picatrix (0.1.0)
5
+ activesupport
6
+ grape
7
+ grape-roar
8
+ parslet
9
+ require_all
10
+ roar
11
+ ruby-graphviz
12
+ sinatra
13
+ sinatra-contrib
14
+ thor
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ activesupport (4.2.4)
20
+ i18n (~> 0.7)
21
+ json (~> 1.7, >= 1.7.7)
22
+ minitest (~> 5.1)
23
+ thread_safe (~> 0.3, >= 0.3.4)
24
+ tzinfo (~> 1.1)
25
+ axiom-types (0.1.1)
26
+ descendants_tracker (~> 0.0.4)
27
+ ice_nine (~> 0.11.0)
28
+ thread_safe (~> 0.3, >= 0.3.1)
29
+ backports (3.6.7)
30
+ blankslate (3.1.3)
31
+ builder (3.2.2)
32
+ coderay (1.1.0)
33
+ coercible (1.0.0)
34
+ descendants_tracker (~> 0.0.1)
35
+ descendants_tracker (0.0.4)
36
+ thread_safe (~> 0.3, >= 0.3.1)
37
+ diff-lcs (1.2.5)
38
+ equalizer (0.0.11)
39
+ grape (0.13.0)
40
+ activesupport
41
+ builder
42
+ hashie (>= 2.1.0)
43
+ multi_json (>= 1.3.2)
44
+ multi_xml (>= 0.5.2)
45
+ rack (>= 1.3.0)
46
+ rack-accept
47
+ rack-mount
48
+ virtus (>= 1.0.0)
49
+ grape-roar (0.3.0)
50
+ grape
51
+ roar (>= 1.0)
52
+ hashie (3.4.3)
53
+ i18n (0.7.0)
54
+ ice_nine (0.11.1)
55
+ json (1.8.3)
56
+ method_source (0.8.2)
57
+ minitest (5.8.2)
58
+ multi_json (1.11.2)
59
+ multi_xml (0.5.5)
60
+ parslet (1.7.1)
61
+ blankslate (>= 2.0, <= 4.0)
62
+ pry (0.10.3)
63
+ coderay (~> 1.1.0)
64
+ method_source (~> 0.8.1)
65
+ slop (~> 3.4)
66
+ rack (1.6.4)
67
+ rack-accept (0.4.5)
68
+ rack (>= 0.4)
69
+ rack-mount (0.8.3)
70
+ rack (>= 1.0.0)
71
+ rack-protection (1.5.3)
72
+ rack
73
+ rack-test (0.6.3)
74
+ rack (>= 1.0)
75
+ rake (10.4.2)
76
+ representable (2.3.0)
77
+ uber (~> 0.0.7)
78
+ require_all (1.3.3)
79
+ roar (1.0.3)
80
+ representable (>= 2.0.1, <= 3.0.0)
81
+ rspec (3.3.0)
82
+ rspec-core (~> 3.3.0)
83
+ rspec-expectations (~> 3.3.0)
84
+ rspec-mocks (~> 3.3.0)
85
+ rspec-core (3.3.2)
86
+ rspec-support (~> 3.3.0)
87
+ rspec-expectations (3.3.1)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.3.0)
90
+ rspec-mocks (3.3.2)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.3.0)
93
+ rspec-support (3.3.0)
94
+ ruby-graphviz (1.2.2)
95
+ sinatra (1.4.6)
96
+ rack (~> 1.4)
97
+ rack-protection (~> 1.4)
98
+ tilt (>= 1.3, < 3)
99
+ sinatra-contrib (1.4.6)
100
+ backports (>= 2.0)
101
+ multi_json
102
+ rack-protection
103
+ rack-test
104
+ sinatra (~> 1.4.0)
105
+ tilt (>= 1.3, < 3)
106
+ slop (3.6.0)
107
+ thor (0.19.1)
108
+ thread_safe (0.3.5)
109
+ tilt (2.0.1)
110
+ tzinfo (1.2.2)
111
+ thread_safe (~> 0.1)
112
+ uber (0.0.15)
113
+ virtus (1.0.5)
114
+ axiom-types (~> 0.1)
115
+ coercible (~> 1.0)
116
+ descendants_tracker (~> 0.0, >= 0.0.3)
117
+ equalizer (~> 0.0, >= 0.0.9)
118
+
119
+ PLATFORMS
120
+ ruby
121
+
122
+ DEPENDENCIES
123
+ bundler (~> 1.10)
124
+ picatrix!
125
+ pry
126
+ rake (~> 10.0)
127
+ rspec
128
+
129
+ BUNDLED WITH
130
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alex Moore-Niemi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ .--.
2
+ /( @ > ,-.
3
+ / ' .'--._/ /
4
+ : , , .'
5
+ '. (___.'_/
6
+ ((-((-''mrf
7
+
8
+ # Picatrix
9
+
10
+ An opinionated hypermedia API generator.
11
+
12
+ Requires:
13
+ - valid `.dot` file (with some specific styles)
14
+
15
+ Outputs:
16
+ - Sinatra style routes
17
+ - `application/vnd.mason+json` assets
18
+ - serializers
19
+ - templates (think forms, not views)
20
+ - state diagram image ([see below](https://github.com/mooreniemi/picatrix#sample-image-output))
21
+
22
+ ## About
23
+
24
+ Directed graphs get complicated, but can be divded into simpler subgraphs. Picatrix is currently useful for only a single workflow (and barely that right now, as we're way before a real release). Integrated workflows will involve generating several route sets that will be required into a single Sinatra app. Some workflows may even be representable as DAGs/trees.
25
+
26
+ The ideal way to use Picatrix is to do an exercise in designing your API "outside in" where all inputs/outputs are defined, and a state diagram is drawn. This diagram can be translated to a dot file, and the inputs/outputs can be translated into hypermedia assets.
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'picatrix'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install picatrix
43
+
44
+ ## Usage
45
+
46
+ In its final state, the intent is to use it as a CLI:
47
+
48
+ ```bash
49
+ $ bin/picapica dg_api.dot app_name
50
+ => generated/app_name.rb
51
+ ```
52
+
53
+ ## Sample Image Output
54
+
55
+ # to generate the image with graphviz installed
56
+ $ dot -Tpng spec/support/dg_api.dot -o spec/support/dg_api.dot.png
57
+
58
+ ![state diagram image of sample app](spec/support/dg_api.dot.png "simple photo viewing app")
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ### TODO
67
+ - generate sinatra routes from app & resource edges
68
+ - initially make mason stubs myself
69
+ - usage will be to iteratively make the necessary templates until routes are filled out
70
+ - with all mason stubs established, make generators for them from
71
+ - RAML?
72
+ - json
73
+ - yml?
74
+
75
+ #### done
76
+ - parse dot file in Ruby
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/mooreniemi/picatrix). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
86
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "picatrix"
5
+
6
+ require "pry"
7
+ pry.start
data/bin/picapica ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
3
+
4
+ require "picatrix"
5
+
6
+ Picatrix::CLI.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/picatrix.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "picatrix/version"
2
+ require "parslet"
3
+ require "graphviz"
4
+ require "active_support"
5
+ require "active_support/core_ext/string"
6
+ require "thor"
7
+
8
+ require "picatrix/pacman"
9
+ require "picatrix/digraph_parser"
10
+ require "picatrix/transform_to_hash"
11
+ require "picatrix/jenny"
12
+
13
+ module Picatrix
14
+ class CLI < Thor
15
+ desc "g <dot file name> <output file name>", "generate <dot file name> <output file name>"
16
+ option :force, :type => :boolean
17
+
18
+ def g(dot_file_name, output=nil)
19
+ puts "using: #{dot_file_name}"
20
+ puts "output: #{output}" if output
21
+
22
+ Jenny.new(
23
+ Pacman.new(dot_file_name).hash,
24
+ options
25
+ ).just_do_it
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,137 @@
1
+ module Picatrix
2
+ class DigraphParser < Parslet::Parser
3
+ rule(:space) { str(" ") }
4
+ rule(:indent) { str(" ").repeat(2) }
5
+ rule(:newline) { str("\n") }
6
+ rule(:eof) { any.absent? }
7
+ rule(:comment) do
8
+ indent.repeat(0) >>
9
+ str("//") >>
10
+ (newline.absent? >> any).repeat(1) >>
11
+ newline
12
+ end
13
+ rule(:default_definitions) do
14
+ indent >>
15
+ str("edge [") >>
16
+ newline >>
17
+ indent.repeat >>
18
+ str("arrowhead=\"odiamond\"") >>
19
+ newline >>
20
+ indent >>
21
+ str("]") >>
22
+ newline
23
+ end
24
+ rule(:arrow) { str("->") }
25
+ rule(:snake_case_key) do
26
+ match('[a-zA-Z0-9_]').repeat(1)
27
+ end
28
+ rule(:quoted_string) do
29
+ str('"') >>
30
+ (
31
+ (str('\\') >> any) | (str('"').absent? >> any)
32
+ ).repeat(1) >>
33
+ str('"')
34
+ end
35
+ rule(:style) do
36
+ str("style=dotted") |
37
+ str("style=bold") |
38
+ delete_marker
39
+ end
40
+ rule(:post_marker) do
41
+ str("arrowhead=normal")
42
+ end
43
+ rule(:delete_marker) do
44
+ str("color=red fontcolor=red")
45
+ end
46
+ rule(:shape) do
47
+ str("shape=note") |
48
+ str("shape=folder") |
49
+ str("shape=rectangle")
50
+ end
51
+ rule(:label) do
52
+ str("[") >>
53
+ str("label=") >>
54
+ quoted_string.as(:label) >>
55
+ space.repeat(0) >>
56
+ style.repeat(0).as(:style) >>
57
+ space.repeat(0) >>
58
+ shape.repeat(0).as(:shape) >>
59
+ str("]")
60
+ end
61
+ rule(:link_relation) do
62
+ str("[") >>
63
+ str("label=") >>
64
+ quoted_string.as(:link_relation) >>
65
+ space.repeat(0) >>
66
+ style.repeat(0).as(:style) >>
67
+ space.repeat(0) >>
68
+ shape.repeat(0).as(:shape) >>
69
+ space.repeat(0) >>
70
+ post_marker.repeat(0).as(:post) >>
71
+ str("]")
72
+ end
73
+ rule(:edge_target) do
74
+ str("{") >>
75
+ space.repeat(0) >>
76
+ snake_case_key >>
77
+ space.repeat(0) >>
78
+ str("}")
79
+ end
80
+ rule(:root_label) do
81
+ str("[xlabel=") >>
82
+ (str("shape=point]").absent? >> any).repeat >>
83
+ str("shape=point]")
84
+ end
85
+ rule(:root_line) do
86
+ indent >>
87
+ snake_case_key >>
88
+ space >>
89
+ root_label
90
+ end
91
+ rule(:digraph_open_tag) { str("digraph d {") }
92
+ rule(:digraph_close_tag) { str("}") >> newline.repeat(0) >> eof }
93
+ rule(:digraph_heading) do
94
+ digraph_open_tag >>
95
+ newline >>
96
+ comment.repeat(0) >>
97
+ default_definitions >>
98
+ newline >>
99
+ comment.repeat(0) >>
100
+ root_of_api
101
+ end
102
+ rule(:root_of_api) do
103
+ root_line.as(:initial_inbound_request) >>
104
+ newline.repeat(1) >>
105
+ (
106
+ digraph_close_tag.absent? >>
107
+ (
108
+ comment |
109
+ node_definition.as(:node) |
110
+ edge_definition.as(:edge)
111
+ ) >>
112
+ newline.repeat(0)
113
+ ).repeat >>
114
+ digraph_close_tag
115
+ end
116
+ rule(:node_definition) do
117
+ indent >>
118
+ snake_case_key.as(:name) >>
119
+ space.repeat(0) >>
120
+ label >>
121
+ newline
122
+ end
123
+ rule(:edge_definition) do
124
+ indent >>
125
+ snake_case_key.as(:outbound) >>
126
+ space.repeat(0) >>
127
+ arrow >>
128
+ space.repeat(0) >>
129
+ edge_target.as(:inbound) >>
130
+ space.repeat(0) >>
131
+ link_relation >>
132
+ newline
133
+ end
134
+ root(:digraph_heading)
135
+ end
136
+
137
+ end