deepsecurity 0.0.19 → 0.0.20
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/CHANGELOG.md +15 -0
- data/Gemfile +5 -0
- data/bin/dsc +4 -61
- data/deepsecurity.gemspec +7 -2
- data/dsc.md +20 -18
- data/lib/deepsecurity.rb +11 -12
- data/lib/deepsecurity/manager.rb +55 -122
- data/lib/deepsecurity/soap_interface.rb +57 -0
- data/lib/deepsecurity/transport_object.rb +5 -1
- data/lib/deepsecurity/transport_objects/anti_malware_event.rb +26 -17
- data/lib/deepsecurity/transport_objects/host.rb +45 -36
- data/lib/deepsecurity/transport_objects/host_detail.rb +17 -45
- data/lib/deepsecurity/transport_objects/host_filter.rb +4 -4
- data/lib/deepsecurity/transport_objects/host_group.rb +38 -29
- data/lib/deepsecurity/transport_objects/id_filter.rb +3 -3
- data/lib/deepsecurity/transport_objects/system_event.rb +1 -1
- data/lib/deepsecurity/transport_objects/time_filter.rb +2 -2
- data/lib/deepsecurity/version.rb +1 -1
- data/lib/dsc/anti_malware_event_command.rb +54 -11
- data/lib/dsc/command.rb +388 -72
- data/lib/dsc/host_detail_command.rb +56 -6
- data/lib/savon_helper.rb +30 -1
- data/lib/savon_helper/caching_object.rb +50 -13
- data/lib/savon_helper/dsl.rb +286 -0
- data/lib/savon_helper/mapping_object.rb +89 -339
- data/lib/savon_helper/soap_interface.rb +77 -0
- data/lib/savon_helper/type_mappings.rb +270 -143
- metadata +8 -6
- data/lib/deepsecurity/ds_object.rb +0 -37
@@ -1,12 +1,20 @@
|
|
1
|
+
# @author Udo Schneider <Udo.Schneider@homeaddress.de>
|
2
|
+
|
1
3
|
module Dsc
|
2
4
|
|
5
|
+
# This class defines the arguments, options and implementation for the `host_detail` command/subcommand.
|
3
6
|
class HostDetailCommand < Command
|
4
7
|
|
5
|
-
|
8
|
+
# DeepSecurity object covered by this class.
|
9
|
+
# @return [DeepSecurity::HostDetail]
|
6
10
|
def self.transport_class
|
7
11
|
DeepSecurity::HostDetail
|
8
12
|
end
|
9
13
|
|
14
|
+
# @!group Fields flag
|
15
|
+
|
16
|
+
# Default fields if no argument is given
|
17
|
+
# @return [Array<String>] Default fields if no argument is given
|
10
18
|
def self.default_fields
|
11
19
|
[
|
12
20
|
# DNS name of system
|
@@ -36,13 +44,53 @@ module Dsc
|
|
36
44
|
]
|
37
45
|
end
|
38
46
|
|
39
|
-
|
47
|
+
# @!endgroup
|
48
|
+
|
49
|
+
# @!group Command definitions
|
50
|
+
|
51
|
+
# Define all commands for this available for this (sub) command_context
|
52
|
+
# @param command_context [CLI::App] The current context of the command.
|
53
|
+
# @return [void]
|
54
|
+
def self.define_commands(command_context)
|
55
|
+
command_context.desc "Access #{transport_class_string()}s"
|
56
|
+
command_context.command command_symbol do |host_detail_command|
|
57
|
+
define_list_command(host_detail_command)
|
58
|
+
define_schema_command(host_detail_command)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Define `list` command_context
|
63
|
+
# @param command_context [CLI::App] The current context of the command.
|
64
|
+
# @yieldparam list_command [GLI::Command] The just defined list command_context
|
65
|
+
# @yield [list_command] Gives the list command_context to the block
|
66
|
+
# @return [void]
|
67
|
+
def self.define_list_command(command_context)
|
68
|
+
super(command_context) do |list_command|
|
69
|
+
define_detail_level_flag(list_command)
|
70
|
+
define_time_format_flag(list_command)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# @!endgroup
|
75
|
+
|
76
|
+
# @!group Command Implementations
|
77
|
+
|
78
|
+
# `list` Implementation.
|
79
|
+
# List all entries of the `transport_class` type according to given filter parameters.
|
80
|
+
# @param options [Hash<Symbol => Object>] Merged global/local options from GLI
|
81
|
+
# @option options [String] :fields The fields to display.
|
82
|
+
# @option options [String] :detail_level Query Level to request.
|
83
|
+
# @param args [Array<String>] Arguments from GLI
|
84
|
+
# @return [void]
|
85
|
+
def list_command(options, args)
|
40
86
|
fields = parse_fields(options[:fields])
|
87
|
+
detail_level = parse_detail_level(options[:detail_level])
|
88
|
+
parse_time_format(options[:time_format])
|
41
89
|
output do |output|
|
42
|
-
authenticate do |
|
90
|
+
authenticate do |manager|
|
43
91
|
hostFilter = DeepSecurity::HostFilter.all_hosts
|
44
92
|
progressBar = ProgressBar.new("host_status", 100) if @show_progress_bar
|
45
|
-
hostDetails =
|
93
|
+
hostDetails = manager.host_details(hostFilter, detail_level)
|
46
94
|
progressBar.set(25) if @show_progress_bar
|
47
95
|
csv = CSV.new(output)
|
48
96
|
csv << fields
|
@@ -50,9 +98,9 @@ module Dsc
|
|
50
98
|
progressBar.inc(75/hostDetails.size) if @show_progress_bar
|
51
99
|
csv << fields.map do |attribute|
|
52
100
|
begin
|
53
|
-
hostDetail.instance_eval(attribute)
|
101
|
+
to_display_string(hostDetail.instance_eval(attribute))
|
54
102
|
rescue => e
|
55
|
-
|
103
|
+
"ERROR (#{e.message})"
|
56
104
|
end
|
57
105
|
end
|
58
106
|
end
|
@@ -60,6 +108,8 @@ module Dsc
|
|
60
108
|
end
|
61
109
|
end
|
62
110
|
end
|
111
|
+
|
112
|
+
# @!endgroup
|
63
113
|
end
|
64
114
|
|
65
115
|
end
|
data/lib/savon_helper.rb
CHANGED
@@ -1,7 +1,36 @@
|
|
1
1
|
# @author Udo Schneider <Udo.Schneider@homeaddress.de>
|
2
2
|
|
3
|
+
require "logger"
|
4
|
+
require "savon"
|
5
|
+
|
3
6
|
require "savon_helper/missing_type_mapping_exception"
|
4
7
|
# require "savon_helper/soap_exception"
|
5
8
|
require "savon_helper/type_mappings"
|
9
|
+
require "savon_helper/dsl"
|
6
10
|
require "savon_helper/mapping_object"
|
7
|
-
require "savon_helper/caching_object"
|
11
|
+
require "savon_helper/caching_object"
|
12
|
+
require "savon_helper/soap_interface"
|
13
|
+
|
14
|
+
unless String.respond_to? :blank
|
15
|
+
|
16
|
+
class String
|
17
|
+
def blank?
|
18
|
+
empty?()
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NilClass
|
23
|
+
def blank?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class Object
|
31
|
+
|
32
|
+
def self.name_without_namespace
|
33
|
+
name.split('::').last || ''
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
# @author Udo Schneider <Udo.Schneider@homeaddress.de>
|
2
2
|
|
3
|
+
require "cache"
|
4
|
+
|
3
5
|
module SavonHelper
|
4
6
|
|
5
7
|
class CachingObject < MappingObject
|
6
8
|
|
7
|
-
@@cache_aspects = Hash.new()
|
9
|
+
@@cache_aspects = Hash.new { |hash, key| hash[key] = Set.new() }
|
10
|
+
@@cache = Cache.new(nil, nil, 10000, 5*60)
|
8
11
|
|
9
|
-
#
|
12
|
+
# @!group Caching
|
10
13
|
|
11
14
|
def self.cache_aspects
|
12
|
-
aspect = @@cache_aspects[self]
|
13
|
-
return aspect if !aspect.nil?
|
14
|
-
@@cache_aspects[self] = Set.new()
|
15
15
|
@@cache_aspects[self]
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.all_cache_aspects
|
19
|
+
self.superclass.all_cache_aspects + cache_aspects()
|
20
|
+
end
|
21
|
+
|
18
22
|
def self.cache_by_aspect(*symbols)
|
19
23
|
symbols.each { |each| cache_aspects.add(each) }
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.cache_key(aspect, value)
|
23
|
-
"#{self}-#{aspect}-#{value}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def cache_aspects
|
27
|
-
self.class.cache_aspects
|
27
|
+
"#{self.name_without_namespace}-#{aspect}-#{value}"
|
28
28
|
end
|
29
29
|
|
30
30
|
def cache_key(aspect)
|
@@ -32,17 +32,54 @@ module SavonHelper
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def cachable?
|
35
|
-
!
|
35
|
+
!all_cache_aspects.empty?
|
36
36
|
end
|
37
37
|
|
38
38
|
def cache
|
39
|
-
|
39
|
+
@@cache
|
40
40
|
end
|
41
41
|
|
42
42
|
def store_in_cache
|
43
|
-
|
43
|
+
all_cache_aspects.each { |aspect| cache.store(self.cache_key(aspect), self) }
|
44
44
|
end
|
45
45
|
|
46
|
+
# @! endgroup
|
47
|
+
|
48
|
+
# @!group Mapping
|
49
|
+
|
50
|
+
# Return an initialized instance with the values from the (type-converted) hash. Store the instance in cache
|
51
|
+
# if cacheable.
|
52
|
+
# @see #store_in_cache
|
53
|
+
#
|
54
|
+
# @param data [Hash] A hash of simple types as provided by Savon
|
55
|
+
# @return [MappingObject] The initialized instance.
|
56
|
+
def self.from_savon(data, interface)
|
57
|
+
instance = super(data, interface)
|
58
|
+
instance.store_in_cache if instance.cachable?
|
59
|
+
instance
|
60
|
+
end
|
61
|
+
|
62
|
+
# @!endgroup
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
class Object
|
68
|
+
|
69
|
+
def cache_aspects
|
70
|
+
self.class.cache_aspects
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.cache_aspects
|
74
|
+
Set.new()
|
75
|
+
end
|
76
|
+
|
77
|
+
def all_cache_aspects
|
78
|
+
self.class.all_cache_aspects
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.all_cache_aspects
|
82
|
+
Set.new()
|
46
83
|
end
|
47
84
|
|
48
85
|
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
module SavonHelper
|
2
|
+
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
public
|
6
|
+
|
7
|
+
# @!group DSL to define attributes mapping
|
8
|
+
|
9
|
+
# @macro [attach] attr_boolean_accessor
|
10
|
+
# @!attribute [rw] $3
|
11
|
+
# $2
|
12
|
+
# @return [Boolean]
|
13
|
+
# Define a new Boolean accessor
|
14
|
+
# @param accessor [Symbol] The accessor to be created
|
15
|
+
# @param description [String] The description for this accessor
|
16
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
17
|
+
# @return [void]
|
18
|
+
def attr_boolean_accessor(accessor, description='', alias_accessor=accessor)
|
19
|
+
create_accessor(accessor, alias_accessor, BooleanMapping.new(description))
|
20
|
+
end
|
21
|
+
|
22
|
+
# @macro [attach] array_boolean_accessor
|
23
|
+
# @!attribute [rw] $3
|
24
|
+
# $2
|
25
|
+
# @return [Array<Boolean>]
|
26
|
+
# Define a new Boolean Array accessor
|
27
|
+
# @param accessor [Symbol] The accessor to be created
|
28
|
+
# @param description [String] The description for this accessor
|
29
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
30
|
+
# @return [void]
|
31
|
+
def array_boolean_accessor(accessor, description='', alias_accessor=accessor)
|
32
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(BooleanMapping.new, description))
|
33
|
+
end
|
34
|
+
|
35
|
+
# @macro [attach] attr_integer_accessor
|
36
|
+
# @!attribute [rw] $3
|
37
|
+
# $2
|
38
|
+
# @return [int]
|
39
|
+
# Define a new Integer accessor
|
40
|
+
# @param accessor [Symbol] The accessor to be created
|
41
|
+
# @param description [String] The description for this accessor
|
42
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
43
|
+
# @return [void]
|
44
|
+
def attr_integer_accessor(accessor, description='', alias_accessor=accessor)
|
45
|
+
create_accessor(accessor, alias_accessor, IntegerMapping.new(description))
|
46
|
+
end
|
47
|
+
|
48
|
+
# @macro [attach] array_integer_accessor
|
49
|
+
# @!attribute [rw] $3
|
50
|
+
# $2
|
51
|
+
# @return [Array<int>]
|
52
|
+
# Define a new Integer Array accessor
|
53
|
+
# @param accessor [Symbol] The accessor to be created
|
54
|
+
# @param description [String] The description for this accessor
|
55
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
56
|
+
# @return [void]
|
57
|
+
def array_integer_accessor(accessor, description='', alias_accessor=accessor)
|
58
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(IntegerMapping.new, description))
|
59
|
+
end
|
60
|
+
|
61
|
+
# @macro [attach] attr_float_accessor
|
62
|
+
# @!attribute [rw] $3
|
63
|
+
# $2
|
64
|
+
# @return [float]
|
65
|
+
# Define a new Float accessor
|
66
|
+
# @param accessor [Symbol] The accessor to be created
|
67
|
+
# @param description [String] The description for this accessor
|
68
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
69
|
+
# @return [void]
|
70
|
+
def attr_float_accessor(accessor, description='', alias_accessor=accessor)
|
71
|
+
create_accessor(accessor, alias_accessor, FloatMapping.new(description))
|
72
|
+
end
|
73
|
+
|
74
|
+
# @macro [attach] array_float__accessor
|
75
|
+
# @!attribute [rw] $3
|
76
|
+
# $2
|
77
|
+
# @return [Array<float>]
|
78
|
+
# Define a new Float array accessor
|
79
|
+
# @param accessor [Symbol] The accessor to be created
|
80
|
+
# @param description [String] The description for this accessor
|
81
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
82
|
+
# @return [void]
|
83
|
+
def array_float__accessor(accessor, description='', alias_accessor=accessor)
|
84
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(FloatMapping.new, description))
|
85
|
+
end
|
86
|
+
|
87
|
+
# @macro [attach] attr_double_accessor
|
88
|
+
# @!attribute [rw] $3
|
89
|
+
# $2
|
90
|
+
# @return [float]
|
91
|
+
# Define a new Float accessor
|
92
|
+
# @param accessor [Symbol] The accessor to be created
|
93
|
+
# @param description [String] The description for this accessor
|
94
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
95
|
+
# @return [void]
|
96
|
+
def attr_double_accessor(accessor, description='', alias_accessor=accessor)
|
97
|
+
create_accessor(accessor, alias_accessor, FloatMapping.new(description))
|
98
|
+
end
|
99
|
+
|
100
|
+
# @macro [attach] array_double__accessor
|
101
|
+
# @!attribute [rw] $3
|
102
|
+
# $2
|
103
|
+
# @return [Array<float>]
|
104
|
+
# Define a new Float Array accessor
|
105
|
+
# @param accessor [Symbol] The accessor to be created
|
106
|
+
# @param description [String] The description for this accessor
|
107
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
108
|
+
# @return [void]
|
109
|
+
def array_double_accessor(accessor, description='', alias_accessor=accessor)
|
110
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(FloatMapping.new, description))
|
111
|
+
end
|
112
|
+
|
113
|
+
# @macro [attach] attr_string_accessor
|
114
|
+
# @!attribute [rw] $3
|
115
|
+
# $2
|
116
|
+
# @return [String]
|
117
|
+
# Define a new String accessor
|
118
|
+
# @param accessor [Symbol] The accessor to be created
|
119
|
+
# @param description [String] The description for this accessor
|
120
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
121
|
+
# @return [void]
|
122
|
+
def attr_string_accessor(accessor, description='', alias_accessor=accessor)
|
123
|
+
create_accessor(accessor, alias_accessor, StringMapping.new(description))
|
124
|
+
end
|
125
|
+
|
126
|
+
# @macro [attach] array_string_accessor
|
127
|
+
# @!attribute [rw] $3
|
128
|
+
# $2
|
129
|
+
# @return [Array<String>]
|
130
|
+
# Define a new String Array accessor
|
131
|
+
# @param accessor [Symbol] The accessor to be created
|
132
|
+
# @param description [String] The description for this accessor
|
133
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
134
|
+
# @return [void]
|
135
|
+
def array_string_accessor(accessor, description='', alias_accessor=accessor)
|
136
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(StringMapping.new, description))
|
137
|
+
end
|
138
|
+
|
139
|
+
# @macro [attach] attr_ip_address_accessor
|
140
|
+
# @!attribute [rw] $3
|
141
|
+
# $2
|
142
|
+
# @return [int]
|
143
|
+
# Define a new IP Address accessor
|
144
|
+
# @param accessor [Symbol] The accessor to be created
|
145
|
+
# @param description [String] The description for this accessor
|
146
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
147
|
+
# @return [void]
|
148
|
+
def attr_ip_address_accessor(accessor, description='', alias_accessor=accessor)
|
149
|
+
create_accessor(accessor, alias_accessor, IPAddressMapping.new(description))
|
150
|
+
end
|
151
|
+
|
152
|
+
# @macro [attach] array_ip_address_accessor
|
153
|
+
# @!attribute [rw] $3
|
154
|
+
# $2
|
155
|
+
# @return [Array<int>]
|
156
|
+
# Define a new IP Address Array accessor
|
157
|
+
# @param accessor [Symbol] The accessor to be created
|
158
|
+
# @param description [String] The description for this accessor
|
159
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
160
|
+
# @return [void]
|
161
|
+
def array_ip_address_accessor(accessor, description='', alias_accessor=accessor)
|
162
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(IPAddressMapping.new, description))
|
163
|
+
end
|
164
|
+
|
165
|
+
# @macro [attach] attr_datetime_accessor
|
166
|
+
# @!attribute [rw] $3
|
167
|
+
# $2
|
168
|
+
# @return [DateTime]
|
169
|
+
# Define a new DateTime accessor
|
170
|
+
# @param accessor [Symbol] The accessor to be created
|
171
|
+
# @param description [String] The description for this accessor
|
172
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
173
|
+
# @return [void]
|
174
|
+
def attr_datetime_accessor(accessor, description='', alias_accessor=accessor)
|
175
|
+
create_accessor(accessor, alias_accessor, DatetimeMapping.new(description))
|
176
|
+
end
|
177
|
+
|
178
|
+
# @macro [attach] array_datetime_accessor
|
179
|
+
# @!attribute [rw] $3
|
180
|
+
# $2
|
181
|
+
# @return [Array<DateTime>]
|
182
|
+
# Define a new DateTime Array accessor
|
183
|
+
# @param accessor [Symbol] The accessor to be created
|
184
|
+
# @param description [String] The description for this accessor
|
185
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
186
|
+
# @return [void]
|
187
|
+
def array_datetime_accessor(accessor, description='', alias_accessor=accessor)
|
188
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(DatetimeMapping.new, description))
|
189
|
+
end
|
190
|
+
|
191
|
+
# @macro [attach] attr_enum_accessor
|
192
|
+
# @!attribute [rw] $4
|
193
|
+
# $3
|
194
|
+
# @return [$2]
|
195
|
+
# Define a new Enum accessor
|
196
|
+
# @param accessor [Symbol] The accessor to be created
|
197
|
+
# @param enum [Enum] An hash of Enum to Symbol mappings
|
198
|
+
# @param description [String] The description for this accessor
|
199
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
200
|
+
# @return [void]
|
201
|
+
def attr_enum_accessor(accessor, enum, description='', alias_accessor=accessor)
|
202
|
+
create_accessor(accessor, alias_accessor, EnumMapping.new(enum, description))
|
203
|
+
end
|
204
|
+
|
205
|
+
# @macro [attach] array_enum_accessor
|
206
|
+
# @!attribute [rw] $4
|
207
|
+
# $3
|
208
|
+
# @return [Array<$2>]
|
209
|
+
# Define a new Enum Array accessor
|
210
|
+
# @param accessor [Symbol] The accessor to be created
|
211
|
+
# @param enum [Enum] An hash of Enum to Symbol mappings
|
212
|
+
# @param description [String] The description for this accessor
|
213
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
214
|
+
# @return [void]
|
215
|
+
def array_enum_accessor(accessor, enum, description='', alias_accessor=accessor)
|
216
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(EnumMapping.new(enum), description))
|
217
|
+
end
|
218
|
+
|
219
|
+
# @macro [attach] hint_object_accessor
|
220
|
+
# @!attribute [rw] $4
|
221
|
+
# $3
|
222
|
+
# @return [$2]
|
223
|
+
# Define a new "hint" for documentation purposes. Please note, that the method has to be define elsewhere!
|
224
|
+
# @param accessor [Symbol] The accessor to be created
|
225
|
+
# @param description [String] The description for this accessor
|
226
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
227
|
+
# @return [void]
|
228
|
+
def hint_object_accessor(accessor, klass, description='', alias_accessor=accessor)
|
229
|
+
create_accessor(accessor, alias_accessor, HintMapping.new(klass, description))
|
230
|
+
end
|
231
|
+
|
232
|
+
# @macro [attach] attr_object_accessor
|
233
|
+
# @!attribute [rw] $4
|
234
|
+
# $3
|
235
|
+
# @return [$2]
|
236
|
+
# Define a new Object accessor
|
237
|
+
# @param accessor [Symbol] The accessor to be created
|
238
|
+
# @param klass [Class] The class of the accessed object
|
239
|
+
# @param description [String] The description for this accessor
|
240
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
241
|
+
# @return [void]
|
242
|
+
def attr_object_accessor(accessor, klass, description='', alias_accessor=accessor)
|
243
|
+
create_accessor(accessor, alias_accessor, ObjectMapping.new(klass, description))
|
244
|
+
end
|
245
|
+
|
246
|
+
# @macro [attach] array_object_accessor
|
247
|
+
# @!attribute [rw] $4
|
248
|
+
# $3
|
249
|
+
# @return [Array<$2>]
|
250
|
+
# Define a new Object Array accessor
|
251
|
+
# @param accessor [Symbol] The accessor to be created
|
252
|
+
# @param klass [Class] The class of the accessed object
|
253
|
+
# @param description [String] The description for this accessor
|
254
|
+
# @param alias_accessor [Symbol] An Alias for the accessor
|
255
|
+
# @return [void]
|
256
|
+
def array_object_accessor(accessor, klass, description='', alias_accessor=accessor)
|
257
|
+
create_accessor(accessor, alias_accessor, ArrayMapping.new(ObjectMapping.new(klass, description)))
|
258
|
+
end
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
# Create the specified accessor and it's alias
|
263
|
+
# @param accessor [Symbol] The accessor
|
264
|
+
# @param alias_accessor [Symbol] The accessor alias
|
265
|
+
# @return [void]
|
266
|
+
def create_accessor(accessor, alias_accessor, mapping)
|
267
|
+
type_mappings[accessor] = mapping
|
268
|
+
attr_accessor accessor
|
269
|
+
create_alias(accessor, alias_accessor)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Create the specified alias
|
273
|
+
# @param accessor [Symbol] The accessor
|
274
|
+
# @param alias_accessor [Symbol] The accessor alias
|
275
|
+
# @return [void]
|
276
|
+
def create_alias(accessor, alias_accessor)
|
277
|
+
if alias_accessor != accessor
|
278
|
+
alias_method alias_accessor, accessor
|
279
|
+
alias_method alias_accessor.to_s + "=", accessor.to_s + "="
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# @!endgroup
|
284
|
+
|
285
|
+
end
|
286
|
+
end
|