shomen-model 0.1.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.
data/.ruby ADDED
@@ -0,0 +1,53 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ authors:
5
+ - name: trans
6
+ email: transfire@gmail.com
7
+ copyrights: []
8
+ requirements:
9
+ - name: detroit
10
+ groups:
11
+ - build
12
+ development: true
13
+ dependencies: []
14
+ alternatives: []
15
+ conflicts: []
16
+ repositories:
17
+ - uri: git://github.com/rubyworks/shomen-model.git
18
+ scm: git
19
+ name: upstream
20
+ resources:
21
+ - uri: http://rubyworks.github.com/shomen-model
22
+ name: home
23
+ type: home
24
+ - uri: http://rubydoc.info/gems/shomen-model/frames
25
+ name: docs
26
+ type: doc
27
+ - uri: http://github.com/rubyworks/shomen-model
28
+ name: code
29
+ type: code
30
+ - uri: http://github.com/rubyworks/shomen-model/issues
31
+ name: bugs
32
+ type: bugs
33
+ - uri: http://groups.google.com/groups/rubyworks-mailinglist
34
+ name: mail
35
+ type: mail
36
+ - uri: http://chat.us.freenode.net/rubyworks
37
+ name: chat
38
+ type: chat
39
+ extra: {}
40
+ load_path:
41
+ - lib
42
+ revision: 0
43
+ created: '2010-07-01'
44
+ summary: Ruby Models for Shomen Documentation Format
45
+ title: Shomen Model
46
+ version: 0.1.0
47
+ name: shomen-model
48
+ description: ! "Shomen defines a standard API documentaiton format for object-oriented
49
+ software\n(Ruby programs in particular) which can be used by documentation interfaces,
50
+ \ne.g. Hypervisor, to render API documentation. Shomen Model is a set of Ruby\nclasses
51
+ the module this format, and can be used to generate Shomen documentation."
52
+ organization: rubyworks
53
+ date: '2012-04-20'
@@ -0,0 +1,7 @@
1
+ --private
2
+ --protected
3
+ -r README.rdoc
4
+ lib/
5
+ -
6
+ [A-Z]*.*
7
+ log/[A-Z].*
@@ -0,0 +1,9 @@
1
+ # RELEASE HISTORY
2
+
3
+ ## 0.1.0 / 2012-04-20
4
+
5
+ Initial release of Shomen Model.
6
+
7
+ Changes:
8
+
9
+ * Happy 1st Release Day!
@@ -0,0 +1,28 @@
1
+ Shomen Model - Ruby Models for Shomen Documentation Format
2
+ (http://github.com/rubyworks/shomen)
3
+
4
+ Copyright (c) 2011 Rubyworks. All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms,
7
+ with or without modification, are permitted provided that the following
8
+ conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ 2. Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ SPDX: BSD-2-Clause
@@ -0,0 +1,82 @@
1
+ # Shomen
2
+
3
+ [Website](http://rubyworks.github.com/shomen) /
4
+ [User Manual](http://github.com/rubyworks/shomen/wiki) /
5
+ [Development](http://github.com/rubyworks/shomen) /
6
+ [Mailing List](http://groups.google.com/groups/rubyworks-mailinglist) /
7
+ [IRC Channel](http://chat.us.freenode.net/rubyworks)
8
+
9
+
10
+ ## Description
11
+
12
+ Shomen is an intermediary documentation model designed for documenting
13
+ object-oriented programming languages, particularly Ruby. The specification
14
+ is a flat mapping, without internal referencing, suitable for storage in both
15
+ YAML and JSON formats.
16
+
17
+
18
+ ## Why?
19
+
20
+ By using a standard intermediary format, documentation parsers need only concern
21
+ themselves with a single output target. And documentation templates in turn only
22
+ need to concern themselves with a single input format regardless of the parsing
23
+ system that was used to generate it.
24
+
25
+
26
+ ## Features
27
+
28
+ * Update a single portable file to update documentation.
29
+ * Site disc footprint is extra small thanks to CDNs.
30
+ * Personalize site design to best fit your project.
31
+ * Test drive others customizations with your own remote docs!
32
+
33
+
34
+ ## Instructions
35
+
36
+ To learn about Shomen in detail please visit:
37
+
38
+ * [User Manual](http://github.com/rubyworks/shomen/wiki)
39
+ * [API Documentation](http://rubyworks.github.com/shomen)
40
+
41
+ Overall usage consists of generating a Shomen documentation file for a
42
+ project. Typical usage looks something like:
43
+
44
+ $ shomen -R -r README.rdoc lib - [A-Z]*.* > doc.json
45
+
46
+ Next you want to pair up your doc.json file with a viewer. Currently that means
47
+ using one of the following:
48
+
49
+ * [HyperVisor](http://github.com/rubyworks/hypervisor)
50
+ * [Rebecca](http://github.com/rubyworks/rebecca)
51
+ * [Rubyfaux](http://github.com/rubyworks/rubyfaux)
52
+
53
+ You can copy any of those repos to your website (e.g. site/) and run with it.
54
+ If you want to try it out locally, we recommend using [thin](http://code.macournoyer.com/thin/)
55
+ to view the site.
56
+
57
+ $ cd site
58
+ $ thin start -A file
59
+
60
+ If you can't use thin, Shomen provides a simplistic rack-based static server
61
+ which can be used.
62
+
63
+ $ cd site
64
+ $ shomen-server
65
+
66
+ Viewers don't necessarily need to be copied. All three above can take
67
+ a `doc={url-to-shomen-json-file}` http parameter and server up the docs remotely.
68
+ You just need to publish your `doc.json` file to a publicly accessible URL.
69
+ Note, I recommend that in this case you name the file more specifically,
70
+ e.g. `myapp-1.0.0.json`.
71
+
72
+ See the viewer projects for more information.
73
+
74
+
75
+ ## Copying
76
+
77
+ Copyright (c) 2010 Rubyworks
78
+
79
+ Shomen is distributed under the terms of the **BSD-2-Clause** license.
80
+
81
+ See License.txt for license details.
82
+
@@ -0,0 +1,35 @@
1
+ # Shomen is an intermediary documentation model designed for documenting
2
+ # object-oriented programming languages, particularly Ruby. The specification
3
+ # is a flat mapping, without internal referencing, suitable for storage in both
4
+ # YAML and JSON formats.
5
+ #
6
+ module Shomen
7
+ end
8
+
9
+ if RUBY_VERSION > '1.9'
10
+ require_relative 'shomen-model/core_ext'
11
+ require_relative 'shomen-model/generator'
12
+ require_relative 'shomen-model/abstract'
13
+ require_relative 'shomen-model/document'
14
+ require_relative 'shomen-model/script'
15
+ require_relative 'shomen-model/module'
16
+ require_relative 'shomen-model/class'
17
+ require_relative 'shomen-model/method'
18
+ require_relative 'shomen-model/attribute'
19
+ # require_relative 'shomen-model/function'
20
+ require_relative 'shomen-model/constant'
21
+ require_relative 'shomen-model/metadata'
22
+ else
23
+ require 'shomen-model/core_ext'
24
+ require 'shomen-model/generator'
25
+ require 'shomen-model/abstract'
26
+ require 'shomen-model/document'
27
+ require 'shomen-model/script'
28
+ require 'shomen-model/module'
29
+ require 'shomen-model/class'
30
+ require 'shomen-model/method'
31
+ require 'shomen-model/attribute'
32
+ # require 'shomen-model/function'
33
+ require 'shomen-model/constant'
34
+ require 'shomen-model/metadata'
35
+ end
@@ -0,0 +1,53 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ authors:
5
+ - name: trans
6
+ email: transfire@gmail.com
7
+ copyrights: []
8
+ requirements:
9
+ - name: detroit
10
+ groups:
11
+ - build
12
+ development: true
13
+ dependencies: []
14
+ alternatives: []
15
+ conflicts: []
16
+ repositories:
17
+ - uri: git://github.com/rubyworks/shomen-model.git
18
+ scm: git
19
+ name: upstream
20
+ resources:
21
+ - uri: http://rubyworks.github.com/shomen-model
22
+ name: home
23
+ type: home
24
+ - uri: http://rubydoc.info/gems/shomen-model/frames
25
+ name: docs
26
+ type: doc
27
+ - uri: http://github.com/rubyworks/shomen-model
28
+ name: code
29
+ type: code
30
+ - uri: http://github.com/rubyworks/shomen-model/issues
31
+ name: bugs
32
+ type: bugs
33
+ - uri: http://groups.google.com/groups/rubyworks-mailinglist
34
+ name: mail
35
+ type: mail
36
+ - uri: http://chat.us.freenode.net/rubyworks
37
+ name: chat
38
+ type: chat
39
+ extra: {}
40
+ load_path:
41
+ - lib
42
+ revision: 0
43
+ created: '2010-07-01'
44
+ summary: Ruby Models for Shomen Documentation Format
45
+ title: Shomen Model
46
+ version: 0.1.0
47
+ name: shomen-model
48
+ description: ! "Shomen defines a standard API documentaiton format for object-oriented
49
+ software\n(Ruby programs in particular) which can be used by documentation interfaces,
50
+ \ne.g. Hypervisor, to render API documentation. Shomen Model is a set of Ruby\nclasses
51
+ the module this format, and can be used to generate Shomen documentation."
52
+ organization: rubyworks
53
+ date: '2012-04-20'
@@ -0,0 +1,114 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ # Base class for all model classes.
6
+ #
7
+ class AbstractPrime
8
+
9
+ # Models use an internal hash to store attributes instead of
10
+ # the usual instance methods.
11
+ #
12
+ # Returns nothing.
13
+ def self.attr_accessor(name)
14
+ name = name.to_s
15
+ define_method(name) do
16
+ self[name]
17
+ end
18
+ define_method(name+'=') do |x|
19
+ self[name] = x
20
+ end
21
+ end
22
+
23
+ # Module type is the "last name" of the module downcased.
24
+ #
25
+ # Returns String of module type.
26
+ def self.type
27
+ name.split('::').last.downcase
28
+ end
29
+
30
+ # Initialize new instance of model.
31
+ #
32
+ # settings - Hash of attribute settings.
33
+ #
34
+ # Returns new model instance.
35
+ def initialize(settings={})
36
+ @table = {}
37
+ settings.each do |k,v|
38
+ s = "#{k}=".gsub('-','_')
39
+ __send__(s,v)
40
+ end
41
+ end
42
+
43
+ # Fetch attribute.
44
+ #
45
+ # key - String of attribute's name.
46
+ #
47
+ # Returns attribute value.
48
+ def [](key)
49
+ @table[key.to_s]
50
+ end
51
+
52
+ # Store attribute.
53
+ #
54
+ # key - String of attribute's name.
55
+ # value - Object as value of attribute.
56
+ #
57
+ # Returns attribute value.
58
+ def []=(k,v)
59
+ @table[k.to_s] = v
60
+ end
61
+
62
+ # Convert attributes to hash, including all nested object
63
+ # that repsond to #to_h.
64
+ #
65
+ # Returns Hash of attribute's key-value pairs.
66
+ def to_h
67
+ t = {}
68
+ @table.each do |k,v|
69
+ if v.respond_to?(:to_h)
70
+ t[k] = v.to_h
71
+ else
72
+ t[k] = v
73
+ end
74
+ end
75
+ t
76
+ end
77
+
78
+ end
79
+
80
+ # Abstract base class for model classes that have a type field,
81
+ # i.e. a `!` field.
82
+ #
83
+ class Abstract < AbstractPrime
84
+
85
+ # Initialize new model instance.
86
+ def initialize(settings={})
87
+ super(settings)
88
+ @table['!'] = self.class.type
89
+ end
90
+
91
+ # Full path name of documentation entry.
92
+ #
93
+ # Returns String.
94
+ attr_accessor :path
95
+
96
+ # Hash of `label => description`.
97
+ #
98
+ # Returns Hash.
99
+ attr_accessor :tags
100
+
101
+ # Type of documentation entry. Valid types are `document`,
102
+ # `script`, `method`, `class_method`, `constant` and, for one
103
+ # entry only, `(metadata)`.
104
+ #
105
+ # Retuns String of documentation entry type.
106
+ def type
107
+ self['!']
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -0,0 +1,23 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Attribute < Method
7
+ #
8
+ def self.type; 'attribute'; end
9
+
10
+ #
11
+ def initialize(settings={})
12
+ super(settings)
13
+ self['!'] = settings['singleton'] ? 'class-attribute' : 'attribute'
14
+ end
15
+
16
+ # 'R', 'W' or 'RW'
17
+ attr_accessor :rw
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,18 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Class < Module
7
+
8
+ #
9
+ def self.type; 'class'; end
10
+
11
+ #
12
+ attr_accessor :superclass
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,32 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Constant < Abstract
7
+ #
8
+ def self.type; 'constant'; end
9
+
10
+ # Constant's basename, must start with a capitalized letter.
11
+ attr_accessor :name
12
+
13
+ #
14
+ attr_accessor :namespace
15
+
16
+ #
17
+ attr_accessor :comment
18
+
19
+ # Format of comment (rdoc, markdown or plain).
20
+ attr_accessor :format
21
+
22
+ #
23
+ attr_accessor :value
24
+
25
+ #
26
+ attr_accessor :files
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def to_h
3
+ self
4
+ end unless method_defined?(:to_h)
5
+ end
@@ -0,0 +1,48 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Document < Abstract
7
+ #
8
+ def self.type
9
+ 'document'
10
+ end
11
+
12
+ #def key=(path)
13
+ # path = '/' + path unless path[0,1] == '/'
14
+ # super(path)
15
+ #end
16
+
17
+ attr_accessor :name
18
+
19
+ #attr_accessor :parent
20
+
21
+ attr_accessor :path
22
+
23
+ # Time stamp when script was last modifed.
24
+ attr_accessor :modified
25
+
26
+ alias :mtime :modified
27
+ alias :mtime= :modified=
28
+
29
+ # Time stamp when script was first created.
30
+ attr_accessor :created
31
+
32
+ alias :ctime :created
33
+ alias :ctime= :created=
34
+
35
+ # Source code URI.
36
+ attr_accessor :uri
37
+
38
+ #
39
+ attr_accessor :text
40
+
41
+ # Format of comment (rdoc, markdown or plain).
42
+ attr_accessor :format
43
+
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,187 @@
1
+ module Shomen
2
+
3
+ begin; gem 'json'; rescue; end
4
+
5
+ require 'yaml'
6
+ require 'json'
7
+
8
+ #require 'shomen-model/metadata'
9
+ #require 'shomen-model'
10
+
11
+ # Shared base class that can be used by generators.
12
+ #
13
+ class Generator
14
+
15
+ # Default output format is JSON.
16
+ DEFAULT_FORMAT = 'json'
17
+
18
+ # Is `$FORCE` set?
19
+ #
20
+ # Return true/false.
21
+ def force?
22
+ $FORCE
23
+ end
24
+
25
+ # Outpu format is eitehr :yaml or :json. The default is :json.
26
+ attr_accessor :format
27
+
28
+ # Flag to include full source code in script entries.
29
+ #
30
+ # Returns true/false.
31
+ attr_accessor :source
32
+
33
+ # URI prefix to link to online documentation.
34
+ #
35
+ # Returns String.
36
+ attr_accessor :webcvs
37
+
38
+ # Name of README file.
39
+ attr_accessor :readme
40
+
41
+ # Markup used for comments. This is typically either :rdoc or :markdown.
42
+ attr_accessor :markup
43
+
44
+ # List of scripts to document.
45
+ attr_accessor :scripts
46
+
47
+ # List of "information documents" to document.
48
+ attr_accessor :documents
49
+
50
+ # Include source code in scripts?
51
+ #
52
+ # Returns true/false.
53
+ def source?
54
+ @soruce
55
+ end
56
+
57
+ private
58
+
59
+ # Initialize new generator.
60
+ #
61
+ # options - Hash of generator options.
62
+ #
63
+ # Returns Generator instance.
64
+ def initialize(options)
65
+ @format = DEFAULT_FORMAT
66
+ @readme = Dir['README*'].first
67
+ @source = false
68
+ @use_cache = false
69
+ @markup = nil
70
+ @scripts = []
71
+ @documents = []
72
+
73
+ options.each do |k,v|
74
+ __send__("#{k}=", v)
75
+ end
76
+ end
77
+
78
+ public
79
+
80
+ # Produce documentation in YAML or JSON format depending
81
+ # on the setting of #format setting.
82
+ #
83
+ # Returns String of either YAML or JSON.
84
+ def produce_format
85
+ case format.to_sym
86
+ when :yaml
87
+ produce_yaml
88
+ else
89
+ produce_json
90
+ end
91
+ end
92
+
93
+ # Alias for #produce_format.
94
+ #
95
+ # Returns String of either YAML or JSON.
96
+ alias to_s produce_format
97
+
98
+ # Documentation table in YAML format.
99
+ #
100
+ # Returns String of YAML.
101
+ def produce_yaml
102
+ produce_table.to_yaml
103
+ end
104
+
105
+ # Documentation table in JSON format.
106
+ #
107
+ # Returns String of JSON.
108
+ def produce_json
109
+ force_encoding(produce_table).to_json
110
+ end
111
+
112
+ # Generates documentation table using rdoc or yard
113
+ # depending on the `adapter` setting.
114
+ #
115
+ # Returns documentation table. [Hash]
116
+ def produce_table
117
+ generate
118
+ end
119
+
120
+ # Project metadata.
121
+ #
122
+ # Returns Metadata instance.
123
+ def project_metadata
124
+ @project_metadata ||= Shomen::Metadata.new
125
+ end
126
+
127
+ private
128
+
129
+
130
+ =begin
131
+ #
132
+ # Remove setting options from command line arguments.
133
+ #
134
+ def remove_options(argv, *options)
135
+ options.each do |opt|
136
+ i = argv.index(opt)
137
+ if i
138
+ argv.delete_at(i)
139
+ argv.delete_at(i)
140
+ end
141
+ end
142
+ argv
143
+ end
144
+
145
+ #
146
+ # Remove flag options from command line arguments.
147
+ #
148
+ def remove_flags(argv, *flags)
149
+ flags.each do |opt|
150
+ i = argv.index(opt)
151
+ if i
152
+ argv.delete_index(i)
153
+ end
154
+ end
155
+ argv
156
+ end
157
+ =end
158
+
159
+ # Force encoding to UTF-8.
160
+ #
161
+ # value - Common core object.
162
+ #
163
+ # Returns object with values encoded to UTF-8.
164
+ def force_encoding(value)
165
+ case value
166
+ when Time,Date
167
+ value = value.dup if value.frozen?
168
+ value.to_s.force_encoding('UTF-8')
169
+ when String
170
+ value = value.dup if value.frozen?
171
+ value.force_encoding('UTF-8')
172
+ when Array
173
+ value.map{ |v| force_encoding(v) }
174
+ when Hash
175
+ new = {}
176
+ value.each do |k,v|
177
+ k = force_encoding(k)
178
+ v = force_encoding(v)
179
+ new[k] = v
180
+ end
181
+ new
182
+ end
183
+ end
184
+
185
+ end
186
+
187
+ end
@@ -0,0 +1,33 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Interface < AbstractPrime
7
+
8
+ # TODO: validate that there is an interface image.
9
+ def initialize(settings={})
10
+ #@table = {'arguments'=>[], 'parameters'=>[]}
11
+ super(settings)
12
+ end
13
+
14
+ # The source code "image" of the method's inteface.
15
+ attr_accessor :signature
16
+
17
+ # Arguments breakdown.
18
+ attr_accessor :arguments
19
+
20
+ # Parameters breakdown.
21
+ attr_accessor :parameters
22
+
23
+ # Block
24
+ attr_accessor :block
25
+
26
+ # Return value.
27
+ attr_accessor :returns
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,83 @@
1
+ require 'yaml'
2
+
3
+ module Shomen
4
+
5
+ # Encapsulate metadata, which preferably comes from a .ruby file,
6
+ # but can fallback to a gemspec.
7
+ #
8
+ class Metadata
9
+ include Enumerable
10
+
11
+ # Present working directoty.
12
+ PWD = Dir.pwd
13
+
14
+ # Glob pattern for looking up gemspec.
15
+ GEMSPEC_PATTERN = '{.gemspec,*.gemspec}'
16
+
17
+ #
18
+ # Initialize new Metadata instance.
19
+ #
20
+ def initialize
21
+ @data = (
22
+ data = {}
23
+ if dotruby
24
+ data.merge!(YAML.load_file(dotruby))
25
+ elsif gemspec
26
+ # prefereably use dotruby library to convert,
27
+ # but wait until it's more mainstream
28
+ require 'rubygems/specification'
29
+ spec = ::Gem::Specification.load(gemspec)
30
+ data['name'] = spec.name,
31
+ data['title'] = spec.name.capitalize,
32
+ data['version'] = spec.version.to_s,
33
+ data['authors'] = [spec.author],
34
+ data['summary'] = spec.summary,
35
+ data['description'] = spec.description,
36
+ data['resources'] = {'homepage' => spec.homepage}
37
+ else
38
+ # TODO: Raise error instead ?
39
+ data['name'] = File.basename(Dir.pwd)
40
+ end
41
+ data['path'] = '(metadata)'
42
+ data['markup'] = 'rdoc' # FIXME
43
+ data
44
+ )
45
+ end
46
+
47
+ #
48
+ def dotruby
49
+ file = File.join(PWD, '.ruby')
50
+ return nil unless File.exist?(file)
51
+ file
52
+ end
53
+
54
+ #
55
+ def gemspec
56
+ file = Dir[File.join(PWD, GEMSPEC_PATTERN)].first
57
+ return nil unless file && File.exist?(file)
58
+ file
59
+ end
60
+
61
+ #
62
+ def [](name)
63
+ @data[name]
64
+ end
65
+
66
+ #
67
+ def size
68
+ @data.size
69
+ end
70
+
71
+ #
72
+ def each(&blk)
73
+ @data.each(&blk)
74
+ end
75
+
76
+ #
77
+ def to_h
78
+ @data
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,101 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Method < Abstract
7
+
8
+ #
9
+ def initialize(settings={})
10
+ super(settings)
11
+ @table['declarations'] ||= []
12
+ end
13
+
14
+ # Method's name.
15
+ attr_accessor :name
16
+
17
+ # Method's namespace.
18
+ attr_accessor :namespace
19
+
20
+ # Comment accompanying method definition.
21
+ attr_accessor :comment
22
+
23
+ # Format of comment (rdoc, markdown or plain).
24
+ attr_accessor :format
25
+
26
+ # Singleton method `true` or `false/nil`.
27
+ attr_accessor :singleton
28
+
29
+ # Delarations is a list of keywords that designates characteristics
30
+ # about a method. Common characteristics include `reader`, `writer`
31
+ # or `accessor` if the method is defined via an attr method; `public`
32
+ # `private` or `protected` given the methods visibility; and `class`
33
+ # or `instance` given the methods scope. Default designations are
34
+ # are impled if not specifically stated, such as `public` and `instance`.
35
+ #
36
+ # Using a declarations list simplifies the Shomen data format by allowing
37
+ # declarations to be freely defined, rather than creating a field for each
38
+ # possible designation possible.
39
+ attr_accessor :declarations
40
+
41
+ # Aliases.
42
+ attr_accessor :aliases
43
+
44
+ # Aliases.
45
+ attr_accessor :alias_for
46
+
47
+ # Breakdown of interfaces signature, arguments, parameters, block argument
48
+ # an return values.
49
+ attr_accessor :interfaces
50
+
51
+ #
52
+ def interfaces=(array)
53
+ self['interfaces'] = (
54
+ array.map do |settings|
55
+ case settings
56
+ when Interface
57
+ settings
58
+ else
59
+ Interface.new(settings)
60
+ end
61
+ end
62
+ )
63
+ end
64
+
65
+ # List of possible returns types.
66
+ attr_accessor :returns
67
+
68
+ # List of possible raised errors.
69
+ attr_accessor :raises
70
+
71
+ # Method generated dynamically?
72
+ attr_accessor :dynamic
73
+
74
+ # Filename.
75
+ attr_accessor :file
76
+
77
+ # Line number.
78
+ attr_accessor :line
79
+
80
+ # Source code.
81
+ attr_accessor :source
82
+
83
+ # Source code language.
84
+ attr_accessor :language
85
+
86
+
87
+ # Deprecated method.
88
+ alias :parent :namespace
89
+
90
+ #
91
+ def to_h
92
+ h = super
93
+ h['!'] = 'method'
94
+ h['interfaces'] = (interfaces || []).map{ |s| s.to_h }
95
+ h
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ end
@@ -0,0 +1,54 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Module < Abstract
7
+
8
+ #
9
+ def self.type; 'module'; end
10
+
11
+ # Method's name.
12
+ attr_accessor :name
13
+
14
+ # Namespace of module is the path of the class or module
15
+ # containing this module.
16
+ attr_accessor :namespace
17
+
18
+ # Comment associated with module.
19
+ attr_accessor :comment
20
+
21
+ # Format of comment (rdoc, markdown or plain).
22
+ attr_accessor :format
23
+
24
+ # Mixins.
25
+ attr_accessor :includes
26
+
27
+ # Metaclass mixins.
28
+ attr_accessor :extensions
29
+
30
+ # Constants defined within this module.
31
+ attr_accessor :constants
32
+
33
+ #
34
+ attr_accessor :modules
35
+
36
+ #
37
+ attr_accessor :classes
38
+
39
+ # List of instance methods defined in the module.
40
+ attr_accessor :methods
41
+
42
+ # List of attributes.
43
+ attr_accessor :accessors
44
+
45
+ # The files in which the module is defined.
46
+ attr_accessor :files
47
+
48
+ #
49
+ alias :fullname :path
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,72 @@
1
+ module Shomen
2
+
3
+ module Model
4
+
5
+ #
6
+ class Script < Document
7
+ #
8
+ def self.type; 'script'; end
9
+
10
+ # Full source code or +nil+ if not provided.
11
+ attr_accessor :source
12
+
13
+ # Route text to source.
14
+ alias :text :source
15
+ alias :text= :source=
16
+
17
+ # TODO: Since we are making source available should we deprecate header and footer,
18
+ # or should we include it if source is excluded ?
19
+
20
+ attr_accessor :header
21
+
22
+ attr_accessor :footer
23
+
24
+ # Source code URI.
25
+ attr_accessor :uri
26
+
27
+ # The lanuage of the script.
28
+ attr_accessor :language
29
+
30
+ # File basename of script path.
31
+ attr_accessor :name
32
+
33
+ # Full path of script, relative to project root.
34
+ attr_accessor :path
35
+
36
+ # Time stamp when script was last modifed.
37
+ attr_accessor :modified
38
+
39
+ alias :mtime :modified
40
+ alias :mtime= :modified=
41
+
42
+ # Time stamp when script was first created.
43
+ attr_accessor :created
44
+
45
+ alias :ctime :created
46
+ alias :ctime= :created=
47
+
48
+ # Other scripts required by this script.
49
+ attr_accessor :requires
50
+
51
+ # TODO: Presently these are not being fully utilized by the parsers, need to fix.
52
+
53
+ # Constants defined by this script.
54
+ attr_accessor :constants
55
+
56
+ # Modules defined by this script.
57
+ attr_accessor :modules
58
+
59
+ # Classes defined by this script.
60
+ attr_accessor :classes
61
+
62
+ # Class methods defined in this script.
63
+ attr_accessor :class_methods
64
+
65
+ # Methods defined in this script.
66
+ attr_accessor :methods
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shomen-model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - trans
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: detroit
16
+ requirement: &22566460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *22566460
25
+ description: ! "Shomen defines a standard API documentaiton format for object-oriented
26
+ software\n(Ruby programs in particular) which can be used by documentation interfaces,
27
+ \ne.g. Hypervisor, to render API documentation. Shomen Model is a set of Ruby\nclasses
28
+ the module this format, and can be used to generate Shomen documentation."
29
+ email:
30
+ - transfire@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - LICENSE.txt
35
+ - HISTORY.md
36
+ - README.md
37
+ files:
38
+ - .ruby
39
+ - .yardopts
40
+ - lib/shomen-model/abstract.rb
41
+ - lib/shomen-model/attribute.rb
42
+ - lib/shomen-model/class.rb
43
+ - lib/shomen-model/constant.rb
44
+ - lib/shomen-model/core_ext.rb
45
+ - lib/shomen-model/document.rb
46
+ - lib/shomen-model/generator.rb
47
+ - lib/shomen-model/interface.rb
48
+ - lib/shomen-model/metadata.rb
49
+ - lib/shomen-model/method.rb
50
+ - lib/shomen-model/module.rb
51
+ - lib/shomen-model/script.rb
52
+ - lib/shomen-model.rb
53
+ - lib/shomen-model.yml
54
+ - LICENSE.txt
55
+ - HISTORY.md
56
+ - README.md
57
+ homepage: http://rubyworks.github.com/shomen-model
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.11
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Ruby Models for Shomen Documentation Format
81
+ test_files: []