activefacts-api 1.9.0 → 1.9.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21a02e9269652ab77d07c778444ba5c502c94c98
4
- data.tar.gz: 6df79ce9c7f637ba80471e3661fc64145b2d3686
3
+ metadata.gz: d49215e86ffa0e5ff4c3c4245834dbe57bca2b69
4
+ data.tar.gz: ffe190be92cd81ceef91f4204ef27d5f7fd0f414
5
5
  SHA512:
6
- metadata.gz: 7039e5fe1a242951fc967ee84e098b1eae9bea18bd2cfdf16d9f914ded12977cf1f72f0bbb75f1a31d4a51aeb268e92e1e9ba2b8e61dae77919605206aaa9724
7
- data.tar.gz: 22f0cf6fa9189e7908fbd81b4a433e8206bee09abfe25f6dd9dc58d669a49daf88ca4a257eb3a31897a98e5182802d75964d587b55c84c4172edb686b6449b36
6
+ metadata.gz: 9be5b953f3e71c05c1f7211ce09fb0c5e21f69b3c519ea58aeaa76323b29ddd82bbb5e3269328b55f41f1d1c75dfd74738a93e01ec4b21b55f1fe00303d992d0
7
+ data.tar.gz: 769cc83b2198f25f2867a8104e8feaa4fa1b88e51df38a4766c5ba6fd802e1826d4fad47da3cfefec05cddd679417f4e51b885fc728a114d3be9f43d9b8a0241
@@ -31,15 +31,11 @@ over the fact population.
31
31
  ]
32
32
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
33
 
34
- spec.add_runtime_dependency(%q<rbtree-pure>, [">= 0.1.1", "~> 0"])
34
+ spec.add_runtime_dependency 'rbtree-pure', [">= 0.1.1", "~> 0"]
35
+ spec.add_runtime_dependency 'tracing', ["~> 2"]
35
36
 
36
37
  spec.add_development_dependency "bundler", ">= 1.10", "~> 1.10.6"
37
38
  spec.add_development_dependency "rake", "~> 10.0"
38
39
  spec.add_development_dependency "rspec", "~> 3.3"
39
-
40
- spec.add_runtime_dependency(%q<ruby-debug>, ["~> 0"]) if RUBY_VERSION < "1.9"
41
- spec.add_runtime_dependency(%q<debugger>, ["~> 1"]) if RUBY_VERSION =~ /^1\.9/ or RUBY_VERSION =~ /^2\.0/
42
- spec.add_runtime_dependency(%q<byebug>, ["~> 1"]) if RUBY_VERSION =~ /^2\.1/
43
- # spec.add_development_dependency(%q<pry>, ["~> 0"]) # rbx, jruby
44
40
  end
45
41
 
@@ -43,4 +43,4 @@ require 'activefacts/api/value' # A Value is an Instance of a va
43
43
  require 'activefacts/api/entity' # An Entity class is an Instance not of a value class
44
44
  require 'activefacts/api/standard_types' # Value classes are augmented so their subclasses may become Value Types
45
45
  require 'activefacts/api/exceptions' # Relevant exceptions
46
- require 'activefacts/tracer'
46
+ require 'tracing'
@@ -246,10 +246,17 @@ module ActiveFacts
246
246
  object_type.all_role_transitive.inject({}) do |hash, (role_name, role)|
247
247
  next hash if !role.unique
248
248
  next hash if role.fact_type.class == ActiveFacts::API::TypeInheritanceFactType
249
- if role.counterpart && role.counterpart.unique && !attrs.include?(role.name) && instance.send(role.getter) != nil
250
- raise "#{object_type.basename} cannot be forked unless a replacement value for #{role.name} is provided"
249
+ old_value = instance.send(role.getter)
250
+ if role.counterpart && role.counterpart.unique && old_value != nil
251
+ # It's a one-to-one which is populated. We must not change the counterpart
252
+ if role.mandatory && !attrs.include?(role.name)
253
+ # and cannot just nullify the value
254
+ raise "#{object_type.basename} cannot be forked unless a replacement value for #{role.name} is provided"
255
+ end
256
+ value = attrs[role_name]
257
+ else
258
+ value = attrs[role_name] || instance.send(role.getter)
251
259
  end
252
- value = attrs[role_name] || instance.send(role.getter)
253
260
  hash[role_name] = value if value != nil
254
261
  hash
255
262
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveFacts
2
2
  module API
3
- VERSION = "1.9.0"
3
+ VERSION = "1.9.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activefacts-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: tracing
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -78,20 +92,6 @@ dependencies:
78
92
  - - "~>"
79
93
  - !ruby/object:Gem::Version
80
94
  version: '3.3'
81
- - !ruby/object:Gem::Dependency
82
- name: byebug
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '1'
88
- type: :runtime
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: '1'
95
95
  description: |2
96
96
 
97
97
  The ActiveFacts API is a Ruby DSL for managing constellations of elementary facts.
@@ -135,7 +135,6 @@ files:
135
135
  - lib/activefacts/api/value.rb
136
136
  - lib/activefacts/api/version.rb
137
137
  - lib/activefacts/api/vocabulary.rb
138
- - lib/activefacts/tracer.rb
139
138
  homepage: https://github.com/cjheath/activefacts-api
140
139
  licenses:
141
140
  - MIT
@@ -1,281 +0,0 @@
1
- #
2
- # ActiveFacts Tracer.
3
- #
4
- # The trace() method supports indented tracing.
5
- #
6
- # Trace keys:
7
- # The first argument is normally a symbol which is the key for related trace calls.
8
- # Set the TRACE environment variable to enable it, or add trace.enable(:key) to a CLI.
9
- # A call to trace without a first symbol argument is always enabled (as if by :all)
10
- #
11
- # Message arguments:
12
- # Each subsequent argument is either
13
- # - a String (or anything that can be join()ed), or
14
- # - a Proc (or anything that can be called) that returns such a string.
15
- # Proc arguments will be called only if the trace key is enabled.
16
- # If the key is enabled (or not present) the Trace strings will be joined and emitted.
17
- #
18
- # Trace blocks:
19
- # A block passed to the trace method will always be called, and trace will always return its value.
20
- # Any trace emitted from within such a block will be indented if the current trace key is enabled.
21
- #
22
- # Special trace key options for nesting blocks:
23
- # - A trace key ending in _ is enabled if the base key is enabled, but enables all
24
- # nested trace calls whether or not their key is enabled.
25
- # - A trace key ending in ? is enabled if the base key is enabled, but is emitted
26
- # only if (and just before) the nested block emits a trace message
27
- #
28
- # Testing whether a trace key is enabled:
29
- # A call to trace with a key but without a block will return true if the key is enabled
30
- #
31
- # A call to trace with no arguments returns the Tracer object itself.
32
- #
33
- # Built-in trace keys and behaviour:
34
- # help - list (at exit) all trace keys that became available during the run
35
- # all - enable all trace keys
36
- # keys - display the trace key for every trace message (automatically enabled by :all)
37
- # debug - prepare a Ruby debugger at the start of the run, so it has the full context available
38
- # firstaid - enter the debugger inside the Exception constructor so you can inspect the local context
39
- # trap - trap SIGINT (^C) in a block that allows inspecting or continuing execution (not all debuggers support this)
40
- # flame - use ruby-prof-flamegraph to display the performance profile as a flame graph using SVG
41
- #
42
- # The debugger is chosen from ENV['DEBUG_PREFERENCE'] or the first to load of: byebug, pry. debugger, ruby-trace
43
- #
44
- # Copyright (c) 2009-2015 Clifford Heath. Read the LICENSE file.
45
- #
46
- module ActiveFacts
47
- (class << self; self; end).class_eval do
48
- attr_accessor :tracer
49
- end
50
-
51
- class Tracer
52
- def initialize
53
- reinitialize
54
- end
55
-
56
- def reinitialize
57
- @indent = 0 # Current nesting level of enabled trace blocks
58
- @nested = false # Set when a block enables all enclosed tracing
59
- @available = {} # Hash of available trace keys, accumulated during the run
60
- @delayed = nil # A delayed message, emitted only if the enclosed block emits tracing
61
-
62
- @keys = {}
63
- if (e = ENV["TRACE"])
64
- e.split(/[^_a-zA-Z0-9]/).each{|k| enable(k) }
65
- end
66
- end
67
-
68
- def trace(*args, &block)
69
- begin
70
- old_indent, old_nested, old_delayed, enabled = @indent, @nested, @delayed, show(*args)
71
- # This monstrosity reduces the steps when single-stepping:
72
- block ? yield : (args.size == 0 ? self : enabled)
73
- ensure
74
- @indent, @nested, @delayed = old_indent, old_nested, old_delayed
75
- end
76
- end
77
-
78
- def available_keys
79
- @available.keys
80
- end
81
-
82
- def enabled? key
83
- !key.empty? && @keys[key.to_sym]
84
- end
85
-
86
- def enabled
87
- @keys.keys
88
- end
89
-
90
- def enable key
91
- if !key.empty? && !@keys[s = key.to_sym]
92
- @keys[s] = true
93
- setup_help if s == :help
94
- setup_flame if s == :flame
95
- else
96
- true
97
- end
98
- end
99
-
100
- def disable key
101
- !key.empty? and @keys.delete(key.to_sym)
102
- end
103
-
104
- def toggle key
105
- if !key.empty?
106
- if enabled?(key)
107
- disable(key)
108
- false
109
- else
110
- enable(key)
111
- true
112
- end
113
- end
114
- end
115
-
116
- def setup_help
117
- at_exit {
118
- $stderr.puts "---\nTracing keys available: #{@available.keys.map{|s| s.to_s}.sort*", "}"
119
- }
120
- end
121
-
122
- def setup_flame
123
- require 'ruby-prof'
124
- require 'ruby-prof-flamegraph'
125
- profile_result = RubyProf.start
126
- at_exit {
127
- profile_result2 = RubyProf.stop
128
- printer = RubyProf::FlameGraphPrinter.new(profile_result2)
129
- data_file = "/tmp/flamedata_#{Process.pid}.txt"
130
- svg_file = "/tmp/flamedata_#{Process.pid}.svg"
131
- flamegraph = File.dirname(__FILE__)+"/flamegraph.pl"
132
- File.popen("tee #{data_file} | perl #{flamegraph} --countname=ms --width=4800 > #{svg_file}", "w") { |f|
133
- printer.print(f, {})
134
- }
135
- STDERR.puts("Flame graph dumped to file:///#{svg_file}")
136
- }
137
- end
138
-
139
- def setup_debugger
140
- begin
141
- require 'ruby-trace '
142
- Debugger.start # (:post_mortem => true) # Some Ruby versions crash on post-mortem debugging
143
- rescue LoadError
144
- # Ok, no debugger, tough luck.
145
- end
146
-
147
- if trace :trap
148
- trap('SIGINT') do
149
- puts "Stopped at:\n\t"+caller*"\n\t"
150
- debugger
151
- true # Stopped on SIGINT
152
- end
153
- end
154
-
155
- errors = []
156
- (
157
- [ENV["DEBUG_PREFERENCE"]].compact +
158
- [
159
- 'byebug',
160
- 'pry',
161
- 'debugger',
162
- 'ruby-trace '
163
- ]
164
- ).each do |debugger|
165
- begin
166
- require debugger
167
- if debugger == 'byebug'
168
- Kernel.class_eval do
169
- alias_method :debugger, :byebug
170
- end
171
- end
172
- ::Debugger.start if (const_get(::Debugger) rescue nil)
173
- return
174
- rescue LoadError => e
175
- errors << e
176
- end
177
- end
178
-
179
- # Report when we couldn't load any debugger
180
- $stderr.p errors
181
- end
182
-
183
- def setup_firstaid
184
- if trace :firstaid
185
- puts "Preparing first aid kit"
186
- ::Exception.class_eval do
187
- alias_method :firstaid_initialize, :initialize
188
-
189
- def initialize *args, &b
190
- send(:firstaid_initialize, *args, &b)
191
- return if NoMethodError === self && message =~ /^undefined method `to_ary' for \#<Gem::Specification/
192
- return if LoadError == self
193
- puts "Stopped due to #{self.class}: #{message} at "+caller*"\n\t"
194
- debugger
195
- true # Stopped in Exception constructor
196
- end
197
- end
198
- end
199
- end
200
-
201
- def display key, msg
202
- puts msg
203
- end
204
-
205
- private
206
- def show(*args)
207
- key, enabled_prefix = *selected?(args)
208
-
209
- # Emit the message if enabled or a parent is:
210
- if enabled_prefix && args.size > 0
211
- message =
212
- "\##{enabled_prefix} " +
213
- ' '*@indent +
214
- args.
215
- map{|a| a.respond_to?(:call) ? a.call : a}.
216
- join(' ')
217
-
218
- if @delayed == true
219
- @delayed = message # Arrange to display this message later, if necessary
220
- elsif @delayed
221
- display key, @delayed # Display a delayed message, then the current one
222
- @delayed = nil
223
- display key, message
224
- else
225
- display key, message
226
- end
227
- end
228
- @indent += (enabled_prefix ? 1 : 0)
229
- !!enabled_prefix
230
- end
231
-
232
- def selected?(args)
233
- # Figure out whether this trace is enabled (itself or by :all), if it nests, and if we should print the key:
234
- key =
235
- if Symbol === args[0]
236
- control = args.shift
237
- case s = control.to_s
238
- when /_\Z/ # Enable all nested trace calls
239
- nested = true
240
- s.sub(/_\Z/, '').to_sym
241
- when /\?\Z/ # Delay this message until a nested active trace
242
- @delayed = true
243
- s.sub(/\?\Z/, '').to_sym
244
- else
245
- control
246
- end
247
- else
248
- :all
249
- end
250
-
251
- @available[key] ||= key # Remember that this trace was requested, for help
252
- if @nested || # This trace is enabled because it's in a nested block
253
- @keys[key] || # This trace is enabled in its own right
254
- @keys[:all] # This trace is enabled because all are
255
- if @keys[:keys] || @keys[:all] # Use a formatting prefix?
256
- enabled_prefix = " %-15s"%key
257
- @keys[key] = enabled_prefix if @keys[key] == true # Save the formatting prefix
258
- else
259
- enabled_prefix = ''
260
- end
261
- @nested ||= nested # Activate nesting, if requested
262
- end
263
-
264
- [key, enabled_prefix]
265
- end
266
-
267
- end
268
- end
269
-
270
- # Make the trace method globally available:
271
- class Object
272
- def trace *args, &block
273
- (ActiveFacts.tracer ||= ActiveFacts::Tracer.new).trace(*args, &block)
274
- end
275
- end
276
-
277
- # Load the ruby debugger before everything else, if requested
278
- if trace(:debug) or trace(:firstaid) or trace(:trap)
279
- trace.setup_debugger
280
- trace.setup_firstaid
281
- end