Class: Legion::Extensions::Handle
- Inherits:
-
Object
- Object
- Legion::Extensions::Handle
- Defined in:
- lib/legion/extensions/handle.rb
Constant Summary collapse
- STATES =
%i[registered loaded starting running stopping stopped failed].freeze
- LOADED_STATES =
%i[loaded starting running stopping].freeze
- DISPATCHABLE_STATES =
%i[loaded starting running].freeze
- RELOAD_STATES =
%i[idle pending updating rolling_back failed].freeze
- DISPATCH_BLOCKING_RELOAD_STATES =
%i[updating rolling_back].freeze
Instance Attribute Summary collapse
-
#absorbers ⇒ Object
readonly
Returns the value of attribute absorbers.
-
#active_version ⇒ Object
readonly
Returns the value of attribute active_version.
-
#actors ⇒ Object
readonly
Returns the value of attribute actors.
-
#gem_dir ⇒ Object
readonly
Returns the value of attribute gem_dir.
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#hot_reloadable ⇒ Object
readonly
Returns the value of attribute hot_reloadable.
-
#last_error ⇒ Object
readonly
Returns the value of attribute last_error.
-
#latest_installed_version ⇒ Object
readonly
Returns the value of attribute latest_installed_version.
-
#lex_name ⇒ Object
readonly
Returns the value of attribute lex_name.
-
#loaded_at ⇒ Object
readonly
Returns the value of attribute loaded_at.
-
#loaded_features ⇒ Object
readonly
Returns the value of attribute loaded_features.
-
#reload_state ⇒ Object
readonly
Returns the value of attribute reload_state.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#runners ⇒ Object
readonly
Returns the value of attribute runners.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #dispatchable? ⇒ Boolean
-
#initialize(**attrs) ⇒ Handle
constructor
A new instance of Handle.
- #loaded? ⇒ Boolean
- #pending_reload? ⇒ Boolean
- #running? ⇒ Boolean
- #to_h ⇒ Object
- #with(**attrs) ⇒ Object
Constructor Details
#initialize(**attrs) ⇒ Handle
Returns a new instance of Handle.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/handle.rb', line 16 def initialize(**attrs) lex_name = attrs.fetch(:lex_name) spec = attrs[:spec] @lex_name = lex_name.to_s @gem_name = (attrs[:gem_name] || lex_name).to_s @spec = spec @active_version = normalize_version(attrs[:active_version] || spec&.version) @latest_installed_version = normalize_version(attrs[:latest_installed_version] || attrs[:installed_version] || @active_version) @state = normalize_state(attrs.fetch(:state, :registered)) @reload_state = normalize_reload_state(attrs.fetch(:reload_state, :idle)) @hot_reloadable = attrs[:hot_reloadable] == true @gem_dir = attrs[:gem_dir] || spec&.gem_dir @loaded_features = Array(attrs.fetch(:loaded_features, [])).dup.freeze @actors = Array(attrs.fetch(:actors, [])).dup.freeze @routes = Array(attrs.fetch(:routes, [])).dup.freeze @tools = Array(attrs.fetch(:tools, [])).dup.freeze @absorbers = Array(attrs.fetch(:absorbers, [])).dup.freeze @runners = Array(attrs.fetch(:runners, [])).dup.freeze @loaded_at = attrs.fetch(:loaded_at, Time.now) @last_error = attrs[:last_error] end |
Instance Attribute Details
#absorbers ⇒ Object (readonly)
Returns the value of attribute absorbers.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def absorbers @absorbers end |
#active_version ⇒ Object (readonly)
Returns the value of attribute active_version.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def active_version @active_version end |
#actors ⇒ Object (readonly)
Returns the value of attribute actors.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def actors @actors end |
#gem_dir ⇒ Object (readonly)
Returns the value of attribute gem_dir.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def gem_dir @gem_dir end |
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def gem_name @gem_name end |
#hot_reloadable ⇒ Object (readonly)
Returns the value of attribute hot_reloadable.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def hot_reloadable @hot_reloadable end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def last_error @last_error end |
#latest_installed_version ⇒ Object (readonly)
Returns the value of attribute latest_installed_version.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def latest_installed_version @latest_installed_version end |
#lex_name ⇒ Object (readonly)
Returns the value of attribute lex_name.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def lex_name @lex_name end |
#loaded_at ⇒ Object (readonly)
Returns the value of attribute loaded_at.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def loaded_at @loaded_at end |
#loaded_features ⇒ Object (readonly)
Returns the value of attribute loaded_features.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def loaded_features @loaded_features end |
#reload_state ⇒ Object (readonly)
Returns the value of attribute reload_state.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def reload_state @reload_state end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def routes @routes end |
#runners ⇒ Object (readonly)
Returns the value of attribute runners.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def runners @runners end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def spec @spec end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def state @state end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
12 13 14 |
# File 'lib/legion/extensions/handle.rb', line 12 def tools @tools end |
Instance Method Details
#dispatchable? ⇒ Boolean
52 53 54 |
# File 'lib/legion/extensions/handle.rb', line 52 def dispatchable? DISPATCHABLE_STATES.include?(state) && !DISPATCH_BLOCKING_RELOAD_STATES.include?(reload_state) end |
#loaded? ⇒ Boolean
38 39 40 |
# File 'lib/legion/extensions/handle.rb', line 38 def loaded? LOADED_STATES.include?(state) end |
#pending_reload? ⇒ Boolean
46 47 48 49 50 |
# File 'lib/legion/extensions/handle.rb', line 46 def pending_reload? return false if active_version.nil? || latest_installed_version.nil? latest_installed_version > active_version end |
#running? ⇒ Boolean
42 43 44 |
# File 'lib/legion/extensions/handle.rb', line 42 def running? state == :running end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/legion/extensions/handle.rb', line 60 def to_h { lex_name: lex_name, gem_name: gem_name, active_version: active_version, latest_installed_version: latest_installed_version, state: state, reload_state: reload_state, hot_reloadable: hot_reloadable, spec: spec, gem_dir: gem_dir, loaded_features: loaded_features, actors: actors, routes: routes, tools: tools, absorbers: absorbers, runners: runners, loaded_at: loaded_at, last_error: last_error } end |
#with(**attrs) ⇒ Object
56 57 58 |
# File 'lib/legion/extensions/handle.rb', line 56 def with(**attrs) self.class.new(**to_h, **attrs) end |