origami-docspring 2.2.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/examples/attachments/attachment.rb +7 -8
- data/examples/attachments/nested_document.rb +6 -5
- data/examples/encryption/encryption.rb +5 -4
- data/examples/events/events.rb +7 -6
- data/examples/flash/flash.rb +10 -9
- data/examples/forms/javascript.rb +14 -13
- data/examples/forms/xfa.rb +67 -66
- data/examples/javascript/hello_world.rb +6 -5
- data/examples/javascript/js_emulation.rb +26 -26
- data/examples/loop/goto.rb +12 -11
- data/examples/loop/named.rb +17 -16
- data/examples/signature/signature.rb +11 -11
- data/examples/uri/javascript.rb +25 -24
- data/examples/uri/open-uri.rb +5 -4
- data/examples/uri/submitform.rb +11 -10
- data/lib/origami/3d.rb +330 -334
- data/lib/origami/acroform.rb +267 -268
- data/lib/origami/actions.rb +266 -278
- data/lib/origami/annotations.rb +659 -670
- data/lib/origami/array.rb +192 -196
- data/lib/origami/boolean.rb +66 -70
- data/lib/origami/catalog.rb +360 -363
- data/lib/origami/collections.rb +132 -133
- data/lib/origami/compound.rb +125 -129
- data/lib/origami/destinations.rb +226 -237
- data/lib/origami/dictionary.rb +155 -154
- data/lib/origami/encryption.rb +967 -923
- data/lib/origami/extensions/fdf.rb +270 -275
- data/lib/origami/extensions/ppklite.rb +323 -328
- data/lib/origami/filespec.rb +170 -173
- data/lib/origami/filters/ascii.rb +162 -167
- data/lib/origami/filters/ccitt/tables.rb +248 -252
- data/lib/origami/filters/ccitt.rb +309 -312
- data/lib/origami/filters/crypt.rb +31 -34
- data/lib/origami/filters/dct.rb +47 -50
- data/lib/origami/filters/flate.rb +57 -60
- data/lib/origami/filters/jbig2.rb +50 -53
- data/lib/origami/filters/jpx.rb +40 -43
- data/lib/origami/filters/lzw.rb +151 -155
- data/lib/origami/filters/predictors.rb +250 -255
- data/lib/origami/filters/runlength.rb +111 -115
- data/lib/origami/filters.rb +319 -325
- data/lib/origami/font.rb +173 -177
- data/lib/origami/functions.rb +62 -66
- data/lib/origami/graphics/colors.rb +203 -208
- data/lib/origami/graphics/instruction.rb +79 -81
- data/lib/origami/graphics/path.rb +141 -144
- data/lib/origami/graphics/patterns.rb +156 -160
- data/lib/origami/graphics/render.rb +51 -47
- data/lib/origami/graphics/state.rb +144 -142
- data/lib/origami/graphics/text.rb +185 -188
- data/lib/origami/graphics/xobject.rb +818 -804
- data/lib/origami/graphics.rb +25 -26
- data/lib/origami/header.rb +63 -65
- data/lib/origami/javascript.rb +718 -651
- data/lib/origami/linearization.rb +284 -285
- data/lib/origami/metadata.rb +156 -135
- data/lib/origami/name.rb +98 -100
- data/lib/origami/null.rb +49 -51
- data/lib/origami/numeric.rb +133 -135
- data/lib/origami/obfuscation.rb +180 -182
- data/lib/origami/object.rb +634 -631
- data/lib/origami/optionalcontent.rb +147 -149
- data/lib/origami/outline.rb +46 -48
- data/lib/origami/outputintents.rb +76 -77
- data/lib/origami/page.rb +637 -596
- data/lib/origami/parser.rb +214 -221
- data/lib/origami/parsers/fdf.rb +44 -45
- data/lib/origami/parsers/pdf/lazy.rb +147 -154
- data/lib/origami/parsers/pdf/linear.rb +104 -109
- data/lib/origami/parsers/pdf.rb +109 -107
- data/lib/origami/parsers/ppklite.rb +44 -46
- data/lib/origami/pdf.rb +886 -896
- data/lib/origami/reference.rb +116 -120
- data/lib/origami/signature.rb +617 -625
- data/lib/origami/stream.rb +560 -558
- data/lib/origami/string.rb +366 -368
- data/lib/origami/template/patterns.rb +50 -52
- data/lib/origami/template/widgets.rb +111 -114
- data/lib/origami/trailer.rb +153 -157
- data/lib/origami/tree.rb +55 -57
- data/lib/origami/version.rb +19 -19
- data/lib/origami/webcapture.rb +87 -90
- data/lib/origami/xfa/config.rb +409 -414
- data/lib/origami/xfa/connectionset.rb +113 -117
- data/lib/origami/xfa/datasets.rb +38 -42
- data/lib/origami/xfa/localeset.rb +33 -37
- data/lib/origami/xfa/package.rb +49 -52
- data/lib/origami/xfa/pdf.rb +54 -59
- data/lib/origami/xfa/signature.rb +33 -37
- data/lib/origami/xfa/sourceset.rb +34 -38
- data/lib/origami/xfa/stylesheet.rb +35 -39
- data/lib/origami/xfa/template.rb +1630 -1634
- data/lib/origami/xfa/xdc.rb +33 -37
- data/lib/origami/xfa/xfa.rb +132 -123
- data/lib/origami/xfa/xfdf.rb +34 -38
- data/lib/origami/xfa/xmpmeta.rb +34 -38
- data/lib/origami/xfa.rb +50 -53
- data/lib/origami/xreftable.rb +462 -462
- data/lib/origami.rb +37 -38
- data/test/test_actions.rb +22 -20
- data/test/test_annotations.rb +54 -52
- data/test/test_forms.rb +23 -21
- data/test/test_native_types.rb +82 -78
- data/test/test_object_tree.rb +25 -24
- data/test/test_pages.rb +43 -41
- data/test/test_pdf.rb +2 -0
- data/test/test_pdf_attachment.rb +23 -21
- data/test/test_pdf_create.rb +16 -15
- data/test/test_pdf_encrypt.rb +69 -66
- data/test/test_pdf_parse.rb +131 -129
- data/test/test_pdf_parse_lazy.rb +53 -53
- data/test/test_pdf_sign.rb +67 -67
- data/test/test_streams.rb +145 -143
- data/test/test_xrefs.rb +46 -45
- metadata +64 -8
data/lib/origami/collections.rb
CHANGED
@@ -1,144 +1,143 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This file is part of Origami, PDF manipulation framework for Ruby
|
5
|
+
# Copyright (C) 2016 Guillaume Delugré.
|
6
|
+
#
|
7
|
+
# Origami is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# Origami is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
2
20
|
|
3
|
-
|
4
|
-
|
21
|
+
module Origami
|
22
|
+
class PDF
|
23
|
+
#
|
24
|
+
# Returns true if the document behaves as a portfolio for embedded files.
|
25
|
+
#
|
26
|
+
def portfolio?
|
27
|
+
self.Catalog.Collection.is_a?(Dictionary)
|
28
|
+
end
|
29
|
+
end
|
5
30
|
|
6
|
-
|
7
|
-
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
9
|
-
(at your option) any later version.
|
31
|
+
class Collection < Dictionary
|
32
|
+
include StandardObject
|
10
33
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
34
|
+
module View
|
35
|
+
DETAILS = :D
|
36
|
+
TILE = :T
|
37
|
+
HIDDEN = :H
|
38
|
+
end
|
15
39
|
|
16
|
-
|
17
|
-
|
40
|
+
class Schema < Dictionary
|
41
|
+
include StandardObject
|
18
42
|
|
19
|
-
|
43
|
+
field :Type, Type: Name, Default: :CollectionSchema
|
44
|
+
end
|
20
45
|
|
21
|
-
|
46
|
+
class Navigator < Dictionary
|
47
|
+
include StandardObject
|
48
|
+
|
49
|
+
module Type
|
50
|
+
FLEX = :Module
|
51
|
+
FLASH = :Default
|
52
|
+
end
|
53
|
+
|
54
|
+
field :SWF, Type: String, Required: true
|
55
|
+
field :Name, Type: String, Required: true
|
56
|
+
field :Desc, Type: String
|
57
|
+
field :Category, Type: String
|
58
|
+
field :ID, Type: String, Required: true
|
59
|
+
field :Version, Type: String
|
60
|
+
field :APIVersion, Type: String, Required: true
|
61
|
+
field :LoadType, Type: Name, Default: Type::FLASH
|
62
|
+
field :Icon, Type: String
|
63
|
+
field :Locale, Type: String
|
64
|
+
field :Strings, Type: NameTreeNode.of(String)
|
65
|
+
field :InitialFields, Type: Schema
|
66
|
+
field :Resources, Type: NameTreeNode.of(Stream), Required: true
|
67
|
+
end
|
22
68
|
|
23
|
-
class
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
69
|
+
class Color < Dictionary
|
70
|
+
include StandardObject
|
71
|
+
|
72
|
+
field :Background, Type: Array.of(Number, length: 3)
|
73
|
+
field :CardBackground, Type: Array.of(Number, length: 3)
|
74
|
+
field :CardBorder, Type: Array.of(Number, length: 3)
|
75
|
+
field :PrimaryText, Type: Array.of(Number, length: 3)
|
76
|
+
field :SecondaryText, Type: Array.of(Number, length: 3)
|
30
77
|
end
|
31
78
|
|
32
|
-
class
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
class Schema < Dictionary
|
42
|
-
include StandardObject
|
43
|
-
|
44
|
-
field :Type, :Type => Name, :Default => :CollectionSchema
|
45
|
-
end
|
46
|
-
|
47
|
-
class Navigator < Dictionary
|
48
|
-
include StandardObject
|
49
|
-
|
50
|
-
module Type
|
51
|
-
FLEX = :Module
|
52
|
-
FLASH = :Default
|
53
|
-
end
|
54
|
-
|
55
|
-
field :SWF, :Type => String, :Required => true
|
56
|
-
field :Name, :Type => String, :Required => true
|
57
|
-
field :Desc, :Type => String
|
58
|
-
field :Category, :Type => String
|
59
|
-
field :ID, :Type => String, :Required => true
|
60
|
-
field :Version, :Type => String
|
61
|
-
field :APIVersion, :Type => String, :Required => true
|
62
|
-
field :LoadType, :Type => Name, :Default => Type::FLASH
|
63
|
-
field :Icon, :Type => String
|
64
|
-
field :Locale, :Type => String
|
65
|
-
field :Strings, :Type => NameTreeNode.of(String)
|
66
|
-
field :InitialFields, :Type => Schema
|
67
|
-
field :Resources, :Type => NameTreeNode.of(Stream), :Required => true
|
68
|
-
end
|
69
|
-
|
70
|
-
class Color < Dictionary
|
71
|
-
include StandardObject
|
72
|
-
|
73
|
-
field :Background, :Type => Array.of(Number, length: 3)
|
74
|
-
field :CardBackground, :Type => Array.of(Number, length: 3)
|
75
|
-
field :CardBorder, :Type => Array.of(Number, length: 3)
|
76
|
-
field :PrimaryText, :Type => Array.of(Number, length: 3)
|
77
|
-
field :SecondaryText, :Type => Array.of(Number, length: 3)
|
78
|
-
end
|
79
|
-
|
80
|
-
class Split < Dictionary
|
81
|
-
include StandardObject
|
82
|
-
|
83
|
-
HORIZONTAL = :H
|
84
|
-
VERTICAL = :V
|
85
|
-
NONE = :N
|
86
|
-
|
87
|
-
field :Direction, :Type => Name
|
88
|
-
field :Position, :Type => Number
|
89
|
-
end
|
90
|
-
|
91
|
-
class Item < Dictionary
|
92
|
-
include StandardObject
|
93
|
-
|
94
|
-
field :Type, :Type => Name, :Default => :CollectionItem
|
95
|
-
end
|
96
|
-
|
97
|
-
class Subitem < Dictionary
|
98
|
-
include StandardObject
|
99
|
-
|
100
|
-
field :Type, :Type => Name, :Default => :CollectionSubitem
|
101
|
-
field :D, :Type => [ String, Number ]
|
102
|
-
field :P, :Type => String
|
103
|
-
end
|
104
|
-
|
105
|
-
class Folder < Dictionary
|
106
|
-
include StandardObject
|
107
|
-
|
108
|
-
field :Type, :Type => Name, :Default => :Folder
|
109
|
-
field :ID, :Type => Integer, :Required => true
|
110
|
-
field :Name, :Type => String, :Required => true
|
111
|
-
field :Parent, :Type => Folder
|
112
|
-
field :Child, :Type => Folder
|
113
|
-
field :Next, :Type => Folder
|
114
|
-
field :CI, :Type => Item
|
115
|
-
field :Desc, :Type => String
|
116
|
-
field :CreationDate, :Type => String
|
117
|
-
field :ModDate, :Type => String
|
118
|
-
field :Thumb, :Type => Stream
|
119
|
-
field :Free, :Type => Array.of(Array.of(Integer, length: 2))
|
120
|
-
end
|
121
|
-
|
122
|
-
class Sort < Dictionary
|
123
|
-
include StandardObject
|
124
|
-
|
125
|
-
field :Type, :Type => Name, :Default => :CollectionSort
|
126
|
-
field :S, :Type => [ Name, Array.of(Name) ]
|
127
|
-
field :A, :Type => [ Boolean, Array.of(Boolean) ]
|
128
|
-
end
|
129
|
-
|
130
|
-
#
|
131
|
-
# Collection fields.
|
132
|
-
#
|
133
|
-
field :Type, :Type => Name, :Default => :Collection
|
134
|
-
field :Schema, :Type => Schema
|
135
|
-
field :D, :Type => String
|
136
|
-
field :View, :Type => Name, :Default => View::DETAILS
|
137
|
-
field :Sort, :Type => Sort
|
138
|
-
field :Navigator, :Type => Navigator, :ExtensionLevel => 3
|
139
|
-
field :Resources, :Type => NameTreeNode.of(Stream), :ExtensionLevel => 3
|
140
|
-
field :Colors, :Type => Color, :ExtensionLevel => 3
|
141
|
-
field :Folders, :Type => Folder, :ExtensionLevel => 3
|
142
|
-
field :Split, :Type => Split, :ExtensionLevel => 3
|
79
|
+
class Split < Dictionary
|
80
|
+
include StandardObject
|
81
|
+
|
82
|
+
HORIZONTAL = :H
|
83
|
+
VERTICAL = :V
|
84
|
+
NONE = :N
|
85
|
+
|
86
|
+
field :Direction, Type: Name
|
87
|
+
field :Position, Type: Number
|
143
88
|
end
|
89
|
+
|
90
|
+
class Item < Dictionary
|
91
|
+
include StandardObject
|
92
|
+
|
93
|
+
field :Type, Type: Name, Default: :CollectionItem
|
94
|
+
end
|
95
|
+
|
96
|
+
class Subitem < Dictionary
|
97
|
+
include StandardObject
|
98
|
+
|
99
|
+
field :Type, Type: Name, Default: :CollectionSubitem
|
100
|
+
field :D, Type: [String, Number]
|
101
|
+
field :P, Type: String
|
102
|
+
end
|
103
|
+
|
104
|
+
class Folder < Dictionary
|
105
|
+
include StandardObject
|
106
|
+
|
107
|
+
field :Type, Type: Name, Default: :Folder
|
108
|
+
field :ID, Type: Integer, Required: true
|
109
|
+
field :Name, Type: String, Required: true
|
110
|
+
field :Parent, Type: Folder
|
111
|
+
field :Child, Type: Folder
|
112
|
+
field :Next, Type: Folder
|
113
|
+
field :CI, Type: Item
|
114
|
+
field :Desc, Type: String
|
115
|
+
field :CreationDate, Type: String
|
116
|
+
field :ModDate, Type: String
|
117
|
+
field :Thumb, Type: Stream
|
118
|
+
field :Free, Type: Array.of(Array.of(Integer, length: 2))
|
119
|
+
end
|
120
|
+
|
121
|
+
class Sort < Dictionary
|
122
|
+
include StandardObject
|
123
|
+
|
124
|
+
field :Type, Type: Name, Default: :CollectionSort
|
125
|
+
field :S, Type: [Name, Array.of(Name)]
|
126
|
+
field :A, Type: [Boolean, Array.of(Boolean)]
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Collection fields.
|
131
|
+
#
|
132
|
+
field :Type, Type: Name, Default: :Collection
|
133
|
+
field :Schema, Type: Schema
|
134
|
+
field :D, Type: String
|
135
|
+
field :View, Type: Name, Default: View::DETAILS
|
136
|
+
field :Sort, Type: Sort
|
137
|
+
field :Navigator, Type: Navigator, ExtensionLevel: 3
|
138
|
+
field :Resources, Type: NameTreeNode.of(Stream), ExtensionLevel: 3
|
139
|
+
field :Colors, Type: Color, ExtensionLevel: 3
|
140
|
+
field :Folders, Type: Folder, ExtensionLevel: 3
|
141
|
+
field :Split, Type: Split, ExtensionLevel: 3
|
142
|
+
end
|
144
143
|
end
|
data/lib/origami/compound.rb
CHANGED
@@ -1,161 +1,157 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
require 'set'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This file is part of Origami, PDF manipulation framework for Ruby
|
5
|
+
# Copyright (C) 2017 Guillaume Delugré.
|
6
|
+
#
|
7
|
+
# Origami is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# Origami is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
22
20
|
|
23
21
|
module Origami
|
22
|
+
#
|
23
|
+
# Module for maintaining internal caches of objects for fast lookup.
|
24
|
+
#
|
25
|
+
module ObjectCache
|
26
|
+
attr_reader :strings_cache, :names_cache, :xref_cache
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
module ObjectCache
|
29
|
-
attr_reader :strings_cache, :names_cache, :xref_cache
|
30
|
-
|
31
|
-
def initialize(*args)
|
32
|
-
super(*args)
|
28
|
+
def initialize(*args)
|
29
|
+
super
|
33
30
|
|
34
|
-
|
35
|
-
|
31
|
+
init_caches
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
34
|
+
def rebuild_caches
|
35
|
+
each do |*items|
|
36
|
+
items.each do |object|
|
37
|
+
object.rebuild_caches if object.is_a?(CompoundObject)
|
38
|
+
cache_object(object)
|
44
39
|
end
|
40
|
+
end
|
41
|
+
end
|
45
42
|
|
46
|
-
|
43
|
+
private
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
def init_caches
|
46
|
+
@strings_cache = Set.new
|
47
|
+
@names_cache = Set.new
|
48
|
+
@xref_cache = {}
|
49
|
+
end
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
def cache_object(object)
|
52
|
+
case object
|
53
|
+
when String then cache_string(object)
|
54
|
+
when Name then cache_name(object)
|
55
|
+
when Reference then cache_reference(object)
|
56
|
+
when CompoundObject then cache_compound(object)
|
57
|
+
end
|
61
58
|
|
62
|
-
|
63
|
-
|
59
|
+
object
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
def cache_compound(object)
|
63
|
+
@strings_cache.merge(object.strings_cache)
|
64
|
+
@names_cache.merge(object.names_cache)
|
65
|
+
@xref_cache.update(object.xref_cache) do |_, cache1, cache2|
|
66
|
+
cache1.concat(cache2)
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
object.strings_cache.clear
|
70
|
+
object.names_cache.clear
|
71
|
+
object.xref_cache.clear
|
72
|
+
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
def cache_string(str)
|
75
|
+
@strings_cache.add(str)
|
76
|
+
end
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
def cache_name(name)
|
79
|
+
@names_cache.add(name)
|
80
|
+
end
|
84
81
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
82
|
+
def cache_reference(ref)
|
83
|
+
@xref_cache[ref] ||= []
|
84
|
+
@xref_cache[ref].push(self)
|
89
85
|
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Module for objects containing other objects.
|
90
|
+
#
|
91
|
+
module CompoundObject
|
92
|
+
include Origami::Object
|
93
|
+
include ObjectCache
|
94
|
+
using TypeConversion
|
90
95
|
|
91
96
|
#
|
92
|
-
#
|
97
|
+
# Returns true if the item is present in the compound object.
|
93
98
|
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
using TypeConversion
|
98
|
-
|
99
|
-
#
|
100
|
-
# Returns true if the item is present in the compound object.
|
101
|
-
#
|
102
|
-
def include?(item)
|
103
|
-
super(item.to_o)
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
# Removes the item from the compound object if present.
|
108
|
-
#
|
109
|
-
def delete(item)
|
110
|
-
obj = super(item.to_o)
|
111
|
-
unlink_object(obj) unless obj.nil?
|
112
|
-
end
|
99
|
+
def include?(item)
|
100
|
+
super(item.to_o)
|
101
|
+
end
|
113
102
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
103
|
+
#
|
104
|
+
# Removes the item from the compound object if present.
|
105
|
+
#
|
106
|
+
def delete(item)
|
107
|
+
obj = super(item.to_o)
|
108
|
+
unlink_object(obj) unless obj.nil?
|
109
|
+
end
|
120
110
|
|
121
|
-
|
122
|
-
|
111
|
+
#
|
112
|
+
# Creates a deep copy of the compound object.
|
113
|
+
# This method can be quite expensive as nested objects are copied too.
|
114
|
+
#
|
115
|
+
def copy
|
116
|
+
obj = update_values(&:copy)
|
123
117
|
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
def update_values(&b)
|
128
|
-
return enum_for(__method__) unless block_given?
|
129
|
-
return self.class.new self.transform_values(&b) if self.respond_to?(:transform_values)
|
130
|
-
return self.class.new self.map(&b) if self.respond_to?(:map)
|
118
|
+
transfer_attributes(obj)
|
119
|
+
end
|
131
120
|
|
132
|
-
|
133
|
-
|
121
|
+
#
|
122
|
+
# Returns a new compound object with updated values based on the provided block.
|
123
|
+
#
|
124
|
+
def update_values(&b)
|
125
|
+
return enum_for(__method__) unless block_given?
|
126
|
+
return self.class.new transform_values(&b) if respond_to?(:transform_values)
|
127
|
+
return self.class.new map(&b) if respond_to?(:map)
|
134
128
|
|
135
|
-
|
136
|
-
|
137
|
-
#
|
138
|
-
def update_values!(&b)
|
139
|
-
return enum_for(__method__) unless block_given?
|
140
|
-
return self.transform_values!(&b) if self.respond_to?(:transform_values!)
|
141
|
-
return self.map!(&b) if self.respond_to?(:map!)
|
129
|
+
raise NotImplementedError, "This object does not implement this method"
|
130
|
+
end
|
142
131
|
|
143
|
-
|
144
|
-
|
132
|
+
#
|
133
|
+
# Modifies the compound object's values based on the provided block.
|
134
|
+
#
|
135
|
+
def update_values!(&b)
|
136
|
+
return enum_for(__method__) unless block_given?
|
137
|
+
return transform_values!(&b) if respond_to?(:transform_values!)
|
138
|
+
return map!(&b) if respond_to?(:map!)
|
145
139
|
|
146
|
-
|
140
|
+
raise NotImplementedError, "This object does not implement this method"
|
141
|
+
end
|
147
142
|
|
148
|
-
|
149
|
-
obj = item.to_o
|
150
|
-
obj.parent = self unless obj.indirect?
|
143
|
+
private
|
151
144
|
|
152
|
-
|
153
|
-
|
145
|
+
def link_object(item)
|
146
|
+
obj = item.to_o
|
147
|
+
obj.parent = self unless obj.indirect?
|
154
148
|
|
155
|
-
|
156
|
-
obj.parent = nil
|
157
|
-
obj
|
158
|
-
end
|
149
|
+
cache_object(obj)
|
159
150
|
end
|
160
151
|
|
152
|
+
def unlink_object(obj)
|
153
|
+
obj.parent = nil
|
154
|
+
obj
|
155
|
+
end
|
156
|
+
end
|
161
157
|
end
|