Class: Pindo::TaskSystem::TaskResources::ResourceInstance
- Inherits:
-
Object
- Object
- Pindo::TaskSystem::TaskResources::ResourceInstance
- Defined in:
- lib/pindo/module/task/task_resources/resource_instance.rb
Overview
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#conflicts_with?(other) ⇒ Boolean
检查是否与另一个资源实例冲突.
-
#directory ⇒ String?
获取目录路径(如果有).
-
#has_directory? ⇒ Boolean
检查是否有目录上下文.
-
#initialize(type, context = {}) ⇒ ResourceInstance
constructor
A new instance of ResourceInstance.
-
#inspect ⇒ String
资源实例的详细描述.
-
#matches?(other) ⇒ Boolean
检查是否匹配另一个资源实例(用于释放资源时查找).
-
#matches_spec?(spec) ⇒ Boolean
检查是否匹配资源规格(Hash 格式).
-
#to_s ⇒ String
资源实例的字符串表示.
Constructor Details
#initialize(type, context = {}) ⇒ ResourceInstance
Returns a new instance of ResourceInstance.
20 21 22 23 24 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 20 def initialize(type, context = {}) raise ArgumentError, "type must be a ResourceType" unless type.is_a?(ResourceType) @type = type @context = context || {} end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
16 17 18 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 16 def context @context end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 16 def type @type end |
Instance Method Details
#conflicts_with?(other) ⇒ Boolean
检查是否与另一个资源实例冲突
29 30 31 32 33 34 35 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 29 def conflicts_with?(other) return false unless other.is_a?(ResourceInstance) return false unless @type.name == other.type.name # 不同类型不冲突 # 委托给资源类型检查冲突逻辑 @type.conflicts?(self, other) end |
#directory ⇒ String?
获取目录路径(如果有)
78 79 80 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 78 def directory @context[:directory] end |
#has_directory? ⇒ Boolean
检查是否有目录上下文
84 85 86 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 84 def has_directory? !@context[:directory].nil? end |
#inspect ⇒ String
资源实例的详细描述
72 73 74 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 72 def inspect "#<ResourceInstance type=#{@type.name} strategy=#{@type.strategy} context=#{@context.inspect}>" end |
#matches?(other) ⇒ Boolean
检查是否匹配另一个资源实例(用于释放资源时查找)
40 41 42 43 44 45 46 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 40 def matches?(other) return false unless other.is_a?(ResourceInstance) return false unless @type.name == other.type.name # 上下文必须完全匹配 @context == other.context end |
#matches_spec?(spec) ⇒ Boolean
检查是否匹配资源规格(Hash 格式)
51 52 53 54 55 56 57 58 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 51 def matches_spec?(spec) return false unless spec.is_a?(Hash) return false unless spec[:type] == @type.name # 提取上下文(除了 :type 之外的所有键) spec_context = spec.reject { |k, _| k == :type } @context == spec_context end |
#to_s ⇒ String
资源实例的字符串表示
62 63 64 65 66 67 68 |
# File 'lib/pindo/module/task/task_resources/resource_instance.rb', line 62 def to_s if @context.empty? "#{@type.name}" else "#{@type.name}(#{@context.inspect})" end end |