openhab-scripting 2.16.2 → 2.19.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/lib/openhab.rb +12 -16
- data/lib/openhab/core/entity_lookup.rb +173 -0
- data/lib/openhab/core/openhab_setup.rb +31 -0
- data/lib/openhab/core/osgi.rb +61 -0
- data/lib/openhab/dsl/actions.rb +105 -0
- data/lib/openhab/dsl/dsl.rb +49 -0
- data/lib/openhab/{core/dsl → dsl}/gems.rb +0 -1
- data/lib/openhab/dsl/group.rb +100 -0
- data/lib/openhab/dsl/items/datetime_item.rb +97 -0
- data/lib/openhab/dsl/items/items.rb +46 -0
- data/lib/openhab/dsl/items/number_item.rb +352 -0
- data/lib/openhab/dsl/items/rollershutter_item.rb +179 -0
- data/lib/openhab/dsl/items/string_item.rb +120 -0
- data/lib/openhab/dsl/monkey_patch/actions/actions.rb +4 -0
- data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/events/events.rb +5 -0
- data/lib/openhab/dsl/monkey_patch/events/item_command.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +35 -0
- data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +33 -0
- data/lib/openhab/dsl/monkey_patch/items/contact_item.rb +61 -0
- data/lib/openhab/dsl/monkey_patch/items/dimmer_item.rb +193 -0
- data/lib/openhab/dsl/monkey_patch/items/group_item.rb +37 -0
- data/lib/openhab/dsl/monkey_patch/items/items.rb +133 -0
- data/lib/openhab/dsl/monkey_patch/items/metadata.rb +281 -0
- data/lib/openhab/dsl/monkey_patch/items/persistence.rb +70 -0
- data/lib/openhab/dsl/monkey_patch/items/switch_item.rb +95 -0
- data/lib/openhab/dsl/monkey_patch/ruby/number.rb +39 -0
- data/lib/openhab/dsl/monkey_patch/ruby/range.rb +47 -0
- data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +8 -0
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +41 -0
- data/lib/openhab/dsl/monkey_patch/ruby/time.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +70 -0
- data/lib/openhab/dsl/monkey_patch/types/on_off_type.rb +51 -0
- data/lib/openhab/dsl/monkey_patch/types/open_closed_type.rb +36 -0
- data/lib/openhab/dsl/monkey_patch/types/percent_type.rb +32 -0
- data/lib/openhab/dsl/monkey_patch/types/quantity_type.rb +69 -0
- data/lib/openhab/dsl/monkey_patch/types/types.rb +9 -0
- data/lib/openhab/dsl/monkey_patch/types/up_down_type.rb +33 -0
- data/lib/openhab/dsl/persistence.rb +25 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +342 -0
- data/lib/openhab/dsl/rules/guard.rb +134 -0
- data/lib/openhab/dsl/rules/property.rb +102 -0
- data/lib/openhab/dsl/rules/rule.rb +116 -0
- data/lib/openhab/dsl/rules/rule_config.rb +151 -0
- data/lib/openhab/dsl/rules/triggers/changed.rb +143 -0
- data/lib/openhab/dsl/rules/triggers/channel.rb +53 -0
- data/lib/openhab/dsl/rules/triggers/command.rb +104 -0
- data/lib/openhab/dsl/rules/triggers/cron.rb +177 -0
- data/lib/openhab/dsl/rules/triggers/trigger.rb +124 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +98 -0
- data/lib/openhab/dsl/states.rb +61 -0
- data/lib/openhab/dsl/things.rb +91 -0
- data/lib/openhab/dsl/time_of_day.rb +232 -0
- data/lib/openhab/dsl/timers.rb +77 -0
- data/lib/openhab/dsl/types/datetime.rb +326 -0
- data/lib/openhab/dsl/types/quantity.rb +290 -0
- data/lib/openhab/dsl/units.rb +39 -0
- data/lib/openhab/log/configuration.rb +21 -0
- data/lib/openhab/log/logger.rb +172 -0
- data/lib/openhab/version.rb +1 -1
- metadata +60 -58
- data/lib/openhab/configuration.rb +0 -16
- data/lib/openhab/core/cron.rb +0 -27
- data/lib/openhab/core/debug.rb +0 -34
- data/lib/openhab/core/dsl.rb +0 -51
- data/lib/openhab/core/dsl/actions.rb +0 -107
- data/lib/openhab/core/dsl/entities.rb +0 -147
- data/lib/openhab/core/dsl/group.rb +0 -102
- data/lib/openhab/core/dsl/items/items.rb +0 -51
- data/lib/openhab/core/dsl/items/number_item.rb +0 -323
- data/lib/openhab/core/dsl/items/string_item.rb +0 -122
- data/lib/openhab/core/dsl/monkey_patch/actions/actions.rb +0 -4
- data/lib/openhab/core/dsl/monkey_patch/actions/script_thing_actions.rb +0 -22
- data/lib/openhab/core/dsl/monkey_patch/events.rb +0 -5
- data/lib/openhab/core/dsl/monkey_patch/events/item_command.rb +0 -13
- data/lib/openhab/core/dsl/monkey_patch/events/item_state_changed.rb +0 -25
- data/lib/openhab/core/dsl/monkey_patch/events/thing_status_info.rb +0 -26
- data/lib/openhab/core/dsl/monkey_patch/items/contact_item.rb +0 -54
- data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +0 -182
- data/lib/openhab/core/dsl/monkey_patch/items/group_item.rb +0 -27
- data/lib/openhab/core/dsl/monkey_patch/items/items.rb +0 -132
- data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +0 -283
- data/lib/openhab/core/dsl/monkey_patch/items/persistence.rb +0 -72
- data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +0 -87
- data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +0 -41
- data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +0 -47
- data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +0 -7
- data/lib/openhab/core/dsl/monkey_patch/ruby/string.rb +0 -43
- data/lib/openhab/core/dsl/monkey_patch/types/decimal_type.rb +0 -60
- data/lib/openhab/core/dsl/monkey_patch/types/on_off_type.rb +0 -41
- data/lib/openhab/core/dsl/monkey_patch/types/open_closed_type.rb +0 -25
- data/lib/openhab/core/dsl/monkey_patch/types/percent_type.rb +0 -23
- data/lib/openhab/core/dsl/monkey_patch/types/quantity_type.rb +0 -58
- data/lib/openhab/core/dsl/monkey_patch/types/types.rb +0 -8
- data/lib/openhab/core/dsl/persistence.rb +0 -27
- data/lib/openhab/core/dsl/property.rb +0 -96
- data/lib/openhab/core/dsl/rule/automation_rule.rb +0 -345
- data/lib/openhab/core/dsl/rule/guard.rb +0 -136
- data/lib/openhab/core/dsl/rule/rule.rb +0 -117
- data/lib/openhab/core/dsl/rule/rule_config.rb +0 -153
- data/lib/openhab/core/dsl/rule/triggers/changed.rb +0 -145
- data/lib/openhab/core/dsl/rule/triggers/channel.rb +0 -55
- data/lib/openhab/core/dsl/rule/triggers/command.rb +0 -106
- data/lib/openhab/core/dsl/rule/triggers/cron.rb +0 -160
- data/lib/openhab/core/dsl/rule/triggers/trigger.rb +0 -126
- data/lib/openhab/core/dsl/rule/triggers/updated.rb +0 -100
- data/lib/openhab/core/dsl/states.rb +0 -63
- data/lib/openhab/core/dsl/things.rb +0 -93
- data/lib/openhab/core/dsl/time_of_day.rb +0 -231
- data/lib/openhab/core/dsl/timers.rb +0 -79
- data/lib/openhab/core/dsl/types/quantity.rb +0 -292
- data/lib/openhab/core/dsl/units.rb +0 -41
- data/lib/openhab/core/log.rb +0 -170
- data/lib/openhab/core/patch_load_path.rb +0 -7
- data/lib/openhab/core/startup_delay.rb +0 -23
- data/lib/openhab/osgi.rb +0 -59
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'java'
|
|
4
|
-
|
|
5
|
-
# Monkey patch range to support case equality of OpenHab "Numeric" Objects
|
|
6
|
-
|
|
7
|
-
module OpenHAB
|
|
8
|
-
module Core
|
|
9
|
-
module DSL
|
|
10
|
-
#
|
|
11
|
-
# MonkeyPatch both Ruby and OpenHAB Objects to support DSL
|
|
12
|
-
#
|
|
13
|
-
module MonkeyPatch
|
|
14
|
-
#
|
|
15
|
-
# MonkeyPatch ruby object to support DSL
|
|
16
|
-
#
|
|
17
|
-
module Ruby
|
|
18
|
-
#
|
|
19
|
-
# Extensions for Range Class to support DimmerItems
|
|
20
|
-
#
|
|
21
|
-
module RangeExtensions
|
|
22
|
-
#
|
|
23
|
-
# Override range === method to support DimmerItems
|
|
24
|
-
#
|
|
25
|
-
# @param [Object] other object to compare for case equals
|
|
26
|
-
#
|
|
27
|
-
# @return [Boolean] if other is DimmerItem and state is covered by range,
|
|
28
|
-
# result from parent Range class if not DimmerItem
|
|
29
|
-
#
|
|
30
|
-
def ===(other)
|
|
31
|
-
return super unless other.is_a? DimmerItem
|
|
32
|
-
|
|
33
|
-
cover? other.state.to_i
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
#
|
|
43
|
-
# Prepend Range class with RangeExtensions
|
|
44
|
-
#
|
|
45
|
-
class Range
|
|
46
|
-
prepend OpenHAB::Core::DSL::MonkeyPatch::Ruby::RangeExtensions
|
|
47
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'openhab/core/dsl/types/quantity'
|
|
4
|
-
|
|
5
|
-
module OpenHAB
|
|
6
|
-
module Core
|
|
7
|
-
module DSL
|
|
8
|
-
module MonkeyPatch
|
|
9
|
-
module Ruby
|
|
10
|
-
#
|
|
11
|
-
# Extend String class
|
|
12
|
-
#
|
|
13
|
-
module StringExtensions
|
|
14
|
-
include OpenHAB::Core
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
# Compares String to another object
|
|
18
|
-
#
|
|
19
|
-
# @param [Object] other object to compare to
|
|
20
|
-
#
|
|
21
|
-
# @return [Boolean] true if the two objects contain the same value, false otherwise
|
|
22
|
-
#
|
|
23
|
-
def ==(other)
|
|
24
|
-
case other
|
|
25
|
-
when OpenHAB::Core::DSL::Types::Quantity, QuantityType
|
|
26
|
-
other == self
|
|
27
|
-
else
|
|
28
|
-
super
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
# Prepend String class with comparison extensions
|
|
40
|
-
#
|
|
41
|
-
class String
|
|
42
|
-
prepend OpenHAB::Core::DSL::MonkeyPatch::Ruby::StringExtensions
|
|
43
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'java'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# MonkeyPatching Decimal Type
|
|
7
|
-
#
|
|
8
|
-
# rubocop:disable Style/ClassAndModuleChildren
|
|
9
|
-
class Java::OrgOpenhabCoreLibraryTypes::DecimalType
|
|
10
|
-
# rubocop:enable Style/ClassAndModuleChildren
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# Compare DecimalType to supplied object
|
|
14
|
-
#
|
|
15
|
-
# @param [Object] other object to compare to
|
|
16
|
-
#
|
|
17
|
-
# @return [Integer] -1,0,1 or nil depending on value supplied, nil comparison to supplied object is not possible.
|
|
18
|
-
#
|
|
19
|
-
def <=>(other)
|
|
20
|
-
logger.trace("#{self.class} #{self} <=> #{other} (#{other.class})")
|
|
21
|
-
case other
|
|
22
|
-
when Numeric
|
|
23
|
-
to_big_decimal.compare_to(other.to_d)
|
|
24
|
-
when Java::OrgOpenhabCoreTypes::UnDefType
|
|
25
|
-
1
|
|
26
|
-
else
|
|
27
|
-
other = other.state if other.respond_to? :state
|
|
28
|
-
compare_to(other)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
#
|
|
33
|
-
# Coerce objects into a DecimalType
|
|
34
|
-
#
|
|
35
|
-
# @param [Object] other object to coerce to a DecimalType if possible
|
|
36
|
-
#
|
|
37
|
-
# @return [Object] Numeric when applicable
|
|
38
|
-
#
|
|
39
|
-
def coerce(other)
|
|
40
|
-
logger.trace("Coercing #{self} as a request from #{other.class}")
|
|
41
|
-
case other
|
|
42
|
-
when Numeric
|
|
43
|
-
[other.to_d, to_big_decimal]
|
|
44
|
-
else
|
|
45
|
-
[other, self]
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
# Compare self to other through the spaceship operator
|
|
51
|
-
#
|
|
52
|
-
# @param [Object] other object to compare to
|
|
53
|
-
#
|
|
54
|
-
# @return [Boolean] True if equals
|
|
55
|
-
#
|
|
56
|
-
def ==(other)
|
|
57
|
-
logger.trace("#{self.class} #{self} == #{other} (#{other.class})")
|
|
58
|
-
(self <=> other).zero?
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'java'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# Monkey patching OnOffType
|
|
7
|
-
#
|
|
8
|
-
# rubocop:disable Style/ClassAndModuleChildren
|
|
9
|
-
class Java::OrgOpenhabCoreLibraryTypes::OnOffType
|
|
10
|
-
# rubocop:enable Style/ClassAndModuleChildren
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# Invert the type
|
|
14
|
-
#
|
|
15
|
-
# @return [Java::OrgOpenhabCoreLibraryTypes::OnOffType] OFF if ON, ON if OFF
|
|
16
|
-
#
|
|
17
|
-
def !
|
|
18
|
-
return OFF if self == ON
|
|
19
|
-
return ON if self == OFF
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Check if the supplied object is case equals to self
|
|
23
|
-
#
|
|
24
|
-
# @param [Object] other object to compare
|
|
25
|
-
#
|
|
26
|
-
# @return [Boolean] True if the other object responds to on?/off? and is in the same state as this object,
|
|
27
|
-
# nil if object cannot be compared
|
|
28
|
-
#
|
|
29
|
-
def ===(other)
|
|
30
|
-
# A case statement here causes and infinite loop
|
|
31
|
-
# rubocop:disable Style/CaseLikeIf
|
|
32
|
-
if self == ON
|
|
33
|
-
other.on? if other.respond_to? :on?
|
|
34
|
-
elsif self == OFF
|
|
35
|
-
other.off? if other.respond_to?('off?')
|
|
36
|
-
else
|
|
37
|
-
false
|
|
38
|
-
end
|
|
39
|
-
# rubocop:enable Style/CaseLikeIf
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'java'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# Monkey patch for DSL use
|
|
7
|
-
#
|
|
8
|
-
# rubocop:disable Style/ClassAndModuleChildren
|
|
9
|
-
class Java::OrgOpenhabCoreLibraryTypes::OpenClosedType
|
|
10
|
-
# rubocop:enable Style/ClassAndModuleChildren
|
|
11
|
-
java_import org.openhab.core.library.items.ContactItem
|
|
12
|
-
|
|
13
|
-
#
|
|
14
|
-
# Check if the supplied object is case equals to self
|
|
15
|
-
#
|
|
16
|
-
# @param [Object] other object to compare
|
|
17
|
-
#
|
|
18
|
-
# @return [Boolean] True if the other object is a ContactItem and has the same state
|
|
19
|
-
#
|
|
20
|
-
def ===(other)
|
|
21
|
-
super unless other.is_a? ContactItem
|
|
22
|
-
|
|
23
|
-
self == other.state
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'java'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# MonkeyPatching PercentType
|
|
7
|
-
#
|
|
8
|
-
# rubocop:disable Style/ClassAndModuleChildren
|
|
9
|
-
class Java::OrgOpenhabCoreLibraryTypes::PercentType
|
|
10
|
-
# rubocop:enable Style/ClassAndModuleChildren
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# Need to override and point to super because default JRuby implementation doesn't point to == of parent class
|
|
14
|
-
#
|
|
15
|
-
# @param [Object] other object to check equality for
|
|
16
|
-
# @return [Boolean] True if other equals self, false otherwise
|
|
17
|
-
#
|
|
18
|
-
# rubocop:disable Lint/UselessMethodDefinition
|
|
19
|
-
def ==(other)
|
|
20
|
-
super
|
|
21
|
-
end
|
|
22
|
-
# rubocop:enable Lint/UselessMethodDefinition
|
|
23
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'java'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# MonkeyPatching QuantityType
|
|
7
|
-
#
|
|
8
|
-
# rubocop:disable Style/ClassAndModuleChildren
|
|
9
|
-
class Java::OrgOpenhabCoreLibraryTypes::QuantityType
|
|
10
|
-
# rubocop:enable Style/ClassAndModuleChildren
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# Compare QuantityType to supplied object
|
|
14
|
-
#
|
|
15
|
-
# @param [Object] other object to compare to
|
|
16
|
-
#
|
|
17
|
-
# @return [Integer] -1,0,1 or nil depending on value supplied, nil comparison to supplied object is not possible.
|
|
18
|
-
#
|
|
19
|
-
def <=>(other)
|
|
20
|
-
logger.trace("#{self.class} #{self} <=> #{other} (#{other.class})")
|
|
21
|
-
case other
|
|
22
|
-
when Java::OrgOpenhabCoreTypes::UnDefType then 1
|
|
23
|
-
when String then self <=> Quantity.new(other)
|
|
24
|
-
when OpenHAB::Core::DSL::Types::Quantity then self <=> other.quantity
|
|
25
|
-
else
|
|
26
|
-
other = other.state if other.respond_to? :state
|
|
27
|
-
compare_to(other)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
# Coerce objects into a QuantityType
|
|
33
|
-
#
|
|
34
|
-
# @param [Object] other object to coerce to a QuantityType if possible
|
|
35
|
-
#
|
|
36
|
-
# @return [Object] Numeric when applicable
|
|
37
|
-
#
|
|
38
|
-
def coerce(other)
|
|
39
|
-
logger.trace("Coercing #{self} as a request from #{other.class}")
|
|
40
|
-
case other
|
|
41
|
-
when String
|
|
42
|
-
[Quantity.new(other), self]
|
|
43
|
-
else
|
|
44
|
-
[other, self]
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
# Compare self to other using the spaceship operator
|
|
50
|
-
#
|
|
51
|
-
# @param [Object] other object to compare to
|
|
52
|
-
#
|
|
53
|
-
# @return [Boolean] True if equals
|
|
54
|
-
#
|
|
55
|
-
def ==(other)
|
|
56
|
-
(self <=> other).zero?
|
|
57
|
-
end
|
|
58
|
-
end
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Monkey patch types
|
|
4
|
-
require 'core/dsl/monkey_patch/types/open_closed_type'
|
|
5
|
-
require 'core/dsl/monkey_patch/types/on_off_type'
|
|
6
|
-
require 'core/dsl/monkey_patch/types/decimal_type'
|
|
7
|
-
require 'core/dsl/monkey_patch/types/percent_type'
|
|
8
|
-
require 'core/dsl/monkey_patch/types/quantity_type'
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OpenHAB
|
|
4
|
-
module Core
|
|
5
|
-
module DSL
|
|
6
|
-
#
|
|
7
|
-
# Provides support for interacting with OpenHAB Persistence service
|
|
8
|
-
#
|
|
9
|
-
module Persistence
|
|
10
|
-
#
|
|
11
|
-
# Sets a thread local variable to set the default persistence service
|
|
12
|
-
# for method calls inside the block
|
|
13
|
-
#
|
|
14
|
-
# @param [Object] Persistence service either as a String or a Symbol
|
|
15
|
-
# @yield [] Block executed in context of the supplied persistence service
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
def persistence(service)
|
|
19
|
-
Thread.current.thread_variable_set(:persistence_service, service)
|
|
20
|
-
yield
|
|
21
|
-
ensure
|
|
22
|
-
Thread.current.thread_variable_set(:persistence_service, nil)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'core/log'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# Provides methods to support DSL properties
|
|
7
|
-
#
|
|
8
|
-
module DSLProperty
|
|
9
|
-
include Logging
|
|
10
|
-
|
|
11
|
-
#
|
|
12
|
-
# Extend the calling object with the property methods
|
|
13
|
-
#
|
|
14
|
-
# @param [Object] base object to extend
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
def self.included(base)
|
|
18
|
-
base.extend PropertyMethods
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
# Methods that support creating properties in the DSL
|
|
23
|
-
#
|
|
24
|
-
module PropertyMethods
|
|
25
|
-
#
|
|
26
|
-
# Dynamically creates a property that acts and an accessor with no arguments
|
|
27
|
-
# and a setter with any number of arguments or a block.
|
|
28
|
-
#
|
|
29
|
-
# @param [String] name of the property
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# rubocop:disable Metrics/MethodLength
|
|
33
|
-
# rubocop:disable Metrics/AbcSize
|
|
34
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
35
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
|
36
|
-
def prop(name)
|
|
37
|
-
# rubocop rules are disabled because this method is dynamically defined on the calling
|
|
38
|
-
# object making calls to other methods in this module impossible, or if done on methods
|
|
39
|
-
# in this module than instance variable belong to the module not the calling class
|
|
40
|
-
define_method(name) do |*args, &block|
|
|
41
|
-
if args.length.zero? && block.nil? == true
|
|
42
|
-
instance_variable_get("@#{name}")
|
|
43
|
-
else
|
|
44
|
-
logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
|
|
45
|
-
if args.length == 1
|
|
46
|
-
instance_variable_set("@#{name}", args.first)
|
|
47
|
-
elsif args.length > 1
|
|
48
|
-
instance_variable_set("@#{name}", args)
|
|
49
|
-
elsif block
|
|
50
|
-
instance_variable_set("@#{name}", block)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
#
|
|
57
|
-
# Dynamically creates a property array acts and an accessor with no arguments
|
|
58
|
-
# and a pushes any number of arguments or a block onto they property array
|
|
59
|
-
# You can provide a block to this method which can be used to check if the provided value is acceptable.
|
|
60
|
-
#
|
|
61
|
-
# @param [String] name of the property
|
|
62
|
-
# @param [String] array_name name of the array to use, defaults to name of property
|
|
63
|
-
# @param [Class] wrapper object to put around elements added to the array
|
|
64
|
-
#
|
|
65
|
-
def prop_array(name, array_name: nil, wrapper: nil)
|
|
66
|
-
define_method(name) do |*args, &block|
|
|
67
|
-
array_name ||= name
|
|
68
|
-
if args.length.zero? && block.nil? == true
|
|
69
|
-
instance_variable_get("@#{array_name}")
|
|
70
|
-
else
|
|
71
|
-
logger.trace("Property '#{name}' called with args(#{args}) and block(#{block})")
|
|
72
|
-
if args.length == 1
|
|
73
|
-
insert = args.first
|
|
74
|
-
elsif args.length > 1
|
|
75
|
-
insert = args
|
|
76
|
-
elsif block
|
|
77
|
-
insert = block
|
|
78
|
-
end
|
|
79
|
-
yield insert if block_given?
|
|
80
|
-
insert = wrapper.new(insert) if wrapper
|
|
81
|
-
instance_variable_set("@#{array_name}", (instance_variable_get("@#{array_name}") || []) << insert)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
return unless array_name
|
|
86
|
-
|
|
87
|
-
define_method(array_name) do
|
|
88
|
-
instance_variable_get("@#{array_name}")
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
# rubocop:enable Metrics/MethodLength
|
|
93
|
-
# rubocop:enable Metrics/AbcSize
|
|
94
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
95
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
|
96
|
-
end
|