xumlidot 0.1.0 → 0.2.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.
@@ -5,13 +5,11 @@ require_relative '../types'
5
5
 
6
6
  module Xumlidot
7
7
  module Parsers
8
-
9
8
  # Save current visibility and restore it after processing
10
9
  module Scope
11
10
  # Maintains current state of method visability
12
11
  class Visibility
13
12
  class << self
14
-
15
13
  def state
16
14
  @state ||= :public
17
15
  end
@@ -30,13 +28,14 @@ module Xumlidot
30
28
  end
31
29
  end
32
30
 
33
- def public(&block)
31
+ def public(&_block)
34
32
  temp_visibility = get_visibility
35
33
  set_visibility
36
34
  yield if block_given?
37
35
  set_visibility(temp_visibility)
38
36
  end
39
37
 
38
+ # rubocop:disable Naming/AccessorMethodName
40
39
  def set_visibility(state = :public)
41
40
  Visibility.send(state)
42
41
  end
@@ -44,11 +43,11 @@ module Xumlidot
44
43
  def get_visibility
45
44
  Visibility.state
46
45
  end
46
+ # rubocop:enable Naming/AccessorMethodName
47
47
 
48
- module_function :set_visibility
49
- module_function :get_visibility
50
- module_function :public
48
+ module_function :set_visibility, :get_visibility, :public
49
+ # module_function :get_visibility
50
+ # module_function :public
51
51
  end
52
-
53
52
  end
54
53
  end
@@ -31,12 +31,18 @@ module Xumlidot
31
31
  #
32
32
  # add(Module C, Module B)
33
33
  #
34
- def add(c)
35
- return if @nesting.constants.find_first(c)
34
+ def add(constant)
35
+ return if @nesting.constants.find_first(constant)
36
36
 
37
- root = @nesting.constants.root_namespace_for(c)
38
- (root.nil? ? @nesting.constants : root.constants) << c
39
- @last_added = c
37
+ root = @nesting.constants.root_namespace_for(constant)
38
+ (root.nil? ? @nesting.constants : root.constants) << constant
39
+ @last_added = constant
40
+ end
41
+
42
+ def pop_last_added
43
+ return if @last_added.nil?
44
+
45
+ @last_added = @nesting.constants.root_namespace_for(@last_added)
40
46
  end
41
47
 
42
48
  class ExternalKlassReferences < Array
@@ -49,7 +55,9 @@ module Xumlidot
49
55
  end
50
56
  end
51
57
 
52
- def resolve_inheritance(constant = nil)
58
+ # rubocop:disable Metrics/AbcSize
59
+ # rubocop:disable Metrics/MethodLength
60
+ def resolve_inheritance(_constant = nil)
53
61
  external_klasses = ExternalKlassReferences.new
54
62
 
55
63
  # The first traversal we are going through finding all
@@ -64,9 +72,7 @@ module Xumlidot
64
72
  # If we reach here we have a superklass
65
73
  @nesting.constants.traverse do |other_klass|
66
74
  if other_klass.definition.superklass_of?(klass.definition.superklass)
67
- if ::Xumlidot::Options.debug == true
68
- STDERR.puts "SETTING SUPERKLASS REFERENCE FOR #{klass} to #{other_klass}"
69
- end
75
+ warn "SETTING SUPERKLASS REFERENCE FOR #{klass} to #{other_klass}" if ::Xumlidot::Options.debug == true
70
76
  klass.superklass.reference = other_klass
71
77
  break
72
78
  end
@@ -90,6 +96,8 @@ module Xumlidot
90
96
  end
91
97
  end
92
98
  end
99
+ # rubocop:enable Metrics/AbcSize
100
+ # rubocop:enable Metrics/MethodLength
93
101
  end
94
102
  end
95
103
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_parser'
2
4
  require 'sexp_processor'
3
5
  require 'ostruct'
4
- require 'pry'
5
6
 
6
7
  require_relative 'parsers/generic'
7
8
  require_relative 'parsers/args'
@@ -26,7 +26,7 @@ module Xumlidot
26
26
  class Argument
27
27
  attr_accessor :assign,
28
28
  :default
29
- # :types # TODO: determine the type of the argument
29
+ # :types # TODO: determine the type of the argument
30
30
 
31
31
  attr_reader :name
32
32
 
@@ -6,7 +6,6 @@ module Xumlidot
6
6
  module Types
7
7
  # Value object for an attribute, i.e. accessor defined
8
8
  # via attr_reader, attr_writer or attribute
9
- #
10
9
  class Attribute
11
10
  attr_accessor :read,
12
11
  :write,
@@ -19,7 +18,7 @@ module Xumlidot
19
18
  end
20
19
 
21
20
  def to_s
22
- "(#{accessibility}) #{@name}"
21
+ accessibility ? "(#{accessibility}) #{@name}" : @name
23
22
  end
24
23
 
25
24
  private
@@ -11,16 +11,16 @@ module Xumlidot
11
11
  # name is a single constant, namespace is the remaining full path
12
12
  #
13
13
  # e.g
14
- # For ::Xumlidot::Types::Constant tne name would be Constant and the
14
+ # For ::Xumlidot::Types::Constant the name would be Constant and the
15
15
  # namespace [Types, Xumlidot]
16
16
  #
17
- # Note I am REALLY not happy with this design ...
17
+ # Note I am REALLY unhappy with this design ...
18
18
  class Constant
19
19
  attr_reader :name,
20
20
  :namespace
21
21
 
22
- attr_accessor :reference # TODO: What IS this? I think I may have thrown this
23
- # in to fix a traversal issue if so...hack!
22
+ # TODO: Appears unused, remove when specs complete
23
+ attr_accessor :reference # I think I may have thrown this in to fix a traversal issue if so...hack!
24
24
 
25
25
  def initialize(name, namespace = nil)
26
26
  @name = name
@@ -17,8 +17,8 @@ module Xumlidot
17
17
 
18
18
  each do |k|
19
19
  k.constants.each do |klass|
20
- found = klass.constants.find_first(constant)
21
- return found unless found.nil?
20
+ found = klass.constants.find_first(constant)
21
+ return found unless found.nil?
22
22
  end
23
23
  end
24
24
  nil
@@ -36,6 +36,7 @@ module Xumlidot
36
36
  each do |k|
37
37
  k.constants.each do |klass|
38
38
  return klass if klass.definition.root_namespace_for?(constant)
39
+
39
40
  found = klass.constants.root_namespace_for(constant)
40
41
  return found unless found.nil?
41
42
  end
@@ -46,13 +46,13 @@ module Xumlidot
46
46
  "#{definition} "
47
47
  end
48
48
 
49
- def add_method(m)
50
- m = m.definition if m.respond_to?(:definition)
49
+ def add_method(method_name)
50
+ method_name = method_name.definition if method_name.respond_to?(:definition)
51
51
 
52
- if m.superclass_method == true
53
- @class_methods << m
52
+ if method_name.superclass_method == true
53
+ @class_methods << method_name
54
54
  else
55
- @instance_methods << m
55
+ @instance_methods << method_name
56
56
  end
57
57
  end
58
58
  end
@@ -16,6 +16,12 @@ module Xumlidot
16
16
  # we store all the method details here including many
17
17
  # which we are not yet using.
18
18
  class MethodSignature
19
+ VISIBILITY_SYMBOLS = {
20
+ public: '+',
21
+ private: '-',
22
+ protected: '#'
23
+ }.freeze
24
+
19
25
  attr_accessor :name, # symbol
20
26
  :args, # Arguments
21
27
  :file, # string
@@ -35,25 +41,11 @@ module Xumlidot
35
41
  private
36
42
 
37
43
  def clean_name
38
- tmp = @name.is_a?(Regexp) ? @name.inspect : @name.to_s
39
-
40
- case tmp
41
- when '<<'
42
- '&lt;&lt;'
43
- else
44
- tmp
45
- end
44
+ @name.is_a?(Regexp) ? @name.inspect : @name.to_s
46
45
  end
47
46
 
48
47
  def visibility_symbol
49
- case @visibility
50
- when :public
51
- '+'
52
- when :private
53
- '-'
54
- when :protected
55
- '#'
56
- end
48
+ VISIBILITY_SYMBOLS[@visibility]
57
49
  end
58
50
 
59
51
  def klass
@@ -12,19 +12,19 @@ module Xumlidot
12
12
 
13
13
  def <<(constant)
14
14
  if constant == '::'
15
- @has_root = true
15
+ @has_root = true # TODO: I don't see this used anywhere, remove?
16
16
  return
17
17
  end
18
18
 
19
19
  @namespace << constant unless @name.nil?
20
- @name ||= constant
20
+ @name ||= constant # rubocop:disable Naming/MemoizedInstanceVariableName
21
21
  end
22
22
 
23
- # Create a klass from the superclass for adding
24
- # to the list of constants.
23
+ # Create a klass from the superclass for adding to the list of constants.
25
24
  def to_klass
26
25
  definition = KlassDefinition.new
27
26
  definition.name << ::Xumlidot::Types::Constant.new(@name, @namespace)
27
+
28
28
  Klass.new(definition)
29
29
  end
30
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'types/method'
2
4
  require_relative 'types/methods'
3
5
  require_relative 'types/instance_methods'
@@ -13,6 +15,5 @@ require_relative 'types/method_signature'
13
15
  require_relative 'types/constants'
14
16
  require_relative 'types/module_definition'
15
17
  require_relative 'types/module'
16
- require_relative 'types/klass'
17
18
  require_relative 'types/attribute'
18
19
  require_relative 'types/attributes'
data/lib/xumlidot.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rubygems'
2
3
  require 'fileutils'
3
4
 
@@ -5,6 +6,7 @@ require_relative 'xumlidot/directory_tree'
5
6
  require_relative 'xumlidot/parsers'
6
7
  require_relative 'xumlidot/diagram'
7
8
  require_relative 'xumlidot/options'
9
+ require_relative 'xumlidot/loader'
8
10
 
9
11
  module Xumlidot
10
12
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,21 @@
1
- require_relative '../lib/xumlidot/types'
2
- require_relative '../lib/xumlidot/parsers'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/xumlidot'
4
+
5
+ # Helpers, pass in the full directory path in order to
6
+ # generate xmi/dot output
7
+ def generate_dot(directory)
8
+ options = ::Xumlidot::Options.parse(['--dot'])
9
+ directories = [directory]
10
+ ::Xumlidot::Loader.new(directories, options).load
11
+ ::Xumlidot::ID.reset
12
+ end
13
+
14
+ # Hmmm, for the to work for xmi we're going to have
15
+ # to make the id generation repeatable rather than random
16
+ def generate_xmi(directory)
17
+ options = ::Xumlidot::Options.parse(['--xmi', '--debug-ids'])
18
+ directories = [directory]
19
+ ::Xumlidot::Loader.new(directories, options).load
20
+ ::Xumlidot::ID.reset
21
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xumlidot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Lee Jackson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2022-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rexml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: ruby_parser
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.22'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.22'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: zeus
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +146,7 @@ files:
118
146
  - lib/xumlidot/diagram/xmi/method.rb
119
147
  - lib/xumlidot/diagram/xmi/superklass.rb
120
148
  - lib/xumlidot/directory_tree.rb
149
+ - lib/xumlidot/loader.rb
121
150
  - lib/xumlidot/options.rb
122
151
  - lib/xumlidot/parsers.rb
123
152
  - lib/xumlidot/parsers/args.rb
@@ -151,7 +180,8 @@ files:
151
180
  homepage: http://github.com/os6sense/xumlidot
152
181
  licenses:
153
182
  - MIT
154
- metadata: {}
183
+ metadata:
184
+ rubygems_mfa_required: 'true'
155
185
  post_install_message:
156
186
  rdoc_options: []
157
187
  require_paths:
@@ -160,14 +190,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
190
  requirements:
161
191
  - - ">="
162
192
  - !ruby/object:Gem::Version
163
- version: '0'
193
+ version: '2.6'
194
+ - - "<"
195
+ - !ruby/object:Gem::Version
196
+ version: '4'
164
197
  required_rubygems_version: !ruby/object:Gem::Requirement
165
198
  requirements:
166
199
  - - ">="
167
200
  - !ruby/object:Gem::Version
168
201
  version: '0'
169
202
  requirements: []
170
- rubygems_version: 3.0.3
203
+ rubygems_version: 3.3.4
171
204
  signing_key:
172
205
  specification_version: 4
173
206
  summary: Generates DOT and XMI for Ruby and Rails UML Class Diagrams.