Class: Celluloid::Supervision::Configuration::Instance
- Inherits:
-
Object
- Object
- Celluloid::Supervision::Configuration::Instance
- Defined in:
- lib/celluloid/supervision/configuration/instance.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Instance Method Summary collapse
- #define(instance, fail = false) ⇒ Object
- #delete(k) ⇒ Object
- #export ⇒ Object
- #get(key) ⇒ Object (also: #[])
-
#initialize(configuration = {}) ⇒ Instance
constructor
A new instance of Instance.
- #injection!(key, proc) ⇒ Object
- #injections!(_procs) ⇒ Object
- #key?(k) ⇒ Boolean
- #merge(values) ⇒ Object
- #merge!(values) ⇒ Object
- #ready?(fail = false) ⇒ Boolean
- #resync_accessors ⇒ Object
- #set(key, value) ⇒ Object (also: #[]=)
Constructor Details
#initialize(configuration = {}) ⇒ Instance
Returns a new instance of Instance.
7 8 9 10 11 12 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 7 def initialize(configuration={}) @state = :initializing # :ready resync_accessors @configuration = configuration define(configuration) if configuration.any? end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 5 def configuration @configuration end |
Instance Method Details
#define(instance, fail = false) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 25 def define(instance, fail=false) fail Configuration::Error::AlreadyDefined if ready? fail invoke_injection(:before_configuration) @configuration = Configuration.(instance) ready? end |
#delete(k) ⇒ Object
101 102 103 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 101 def delete(k) @configuration.delete(k) end |
#export ⇒ Object
14 15 16 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 14 def export @configuration.select { |k, v| !REMOVE_AT_EXPORT.include? k } end |
#get(key) ⇒ Object Also known as: []
96 97 98 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 96 def get(key) @configuration[key] end |
#injection!(key, proc) ⇒ Object
32 33 34 35 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 32 def injection!(key, proc) @configuration[:injections] ||= {} @configuration[:injections][key] = proc end |
#injections!(_procs) ⇒ Object
37 38 39 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 37 def injections!(_procs) @configuration[:injections] = proces end |
#key?(k) ⇒ Boolean
87 88 89 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 87 def key?(k) @configuration.key?(k) end |
#merge(values) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 77 def merge(values) if values.is_a? Configuration @configuration.merge(values.configuration) elsif values.is_a? Hash @configuration.merge(values) else fail Error::Invalid end end |
#merge!(values) ⇒ Object
73 74 75 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 73 def merge!(values) @configuration = @configuration.merge(values) end |
#ready?(fail = false) ⇒ Boolean
18 19 20 21 22 23 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 18 def ready?(fail=false) unless @state == :ready @state = :ready if Configuration.valid? @configuration, fail end @state == :ready end |
#resync_accessors ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 41 def resync_accessors # methods for setting and getting the usual defaults Configuration.parameters(:mandatory, :optional, :plugins, :meta).each do |key| self.class.instance_eval do remove_method :"#{key}!" rescue nil # avoid warnings in tests define_method(:"#{key}!") { |value| @configuration[key] = value } end self.class.instance_eval do remove_method :"#{key}=" rescue nil # avoid warnings in tests define_method(:"#{key}=") { |value| @configuration[key] = value } end self.class.instance_eval do remove_method :"#{key}?" rescue nil # avoid warnings in tests define_method(:"#{key}?") { !@configuration[key].nil? } end self.class.instance_eval do remove_method :"#{key}" rescue nil # avoid warnings in tests define_method(:"#{key}") { @configuration[key] } end end Configuration.aliases.each do |_alias, _original| ["!", :"=", :"?", :""]. each do |m| self.class.instance_eval do remove_method :"#{_alias}#{m}" rescue nil # avoid warnings in tests alias_method :"#{_alias}#{m}", :"#{_original}#{m}" end end end true end |
#set(key, value) ⇒ Object Also known as: []=
91 92 93 |
# File 'lib/celluloid/supervision/configuration/instance.rb', line 91 def set(key, value) @configuration[key] = value end |