Class: Bcome::Registry::Loader
- Inherits:
-
Object
- Object
- Bcome::Registry::Loader
- Includes:
- Singleton
- Defined in:
- lib/objects/registry/loader.rb
Constant Summary collapse
- FILE_PATH =
'bcome/registry.yml'.freeze
Instance Method Summary collapse
- #data ⇒ Object
- #do_load ⇒ Object
- #init_new_command_group(node) ⇒ Object
- #restrict_config?(node, command_config) ⇒ Boolean
- #restriction_to_node_klass_mappings ⇒ Object
- #set_command_group_for_node(node) ⇒ Object
Instance Method Details
#data ⇒ Object
7 8 9 |
# File 'lib/objects/registry/loader.rb', line 7 def data @data ||= do_load end |
#do_load ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/objects/registry/loader.rb', line 67 def do_load return {} unless File.exist?(FILE_PATH) begin file_data = YAML.load_file(FILE_PATH).deep_symbolize_keys rescue Psych::SyntaxError => e raise Bcome::Exception::InvalidRegistryDataConfig, "Error: #{e.}" end file_data end |
#init_new_command_group(node) ⇒ Object
44 45 46 |
# File 'lib/objects/registry/loader.rb', line 44 def init_new_command_group(node) ::Bcome::Registry::Command::Group.new(node) end |
#restrict_config?(node, command_config) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/objects/registry/loader.rb', line 48 def restrict_config?(node, command_config) return false unless command_config.key?(:restrict_to_node) node_klass_mapping = restriction_to_node_klass_mappings[command_config[:restrict_to_node].to_sym] unless node_klass_mapping raise Bcome::Exception::InvalidRestrictionKeyInRegistry, "'#{command_config[:restrict_to_node]}' is invalid. Valid keys: #{restriction_to_node_klass_mappings.keys.join(', ')}" end !node.is_a?(node_klass_mapping) end |
#restriction_to_node_klass_mappings ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/objects/registry/loader.rb', line 59 def restriction_to_node_klass_mappings { server: ::Bcome::Node::Server::Base, inventory: ::Bcome::Node::Inventory, collection: ::Bcome::Node::Collection } end |
#set_command_group_for_node(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/objects/registry/loader.rb', line 11 def set_command_group_for_node(node) if group_for_node = ::Bcome::Registry::CommandList.instance.group_for_node(node) return group_for_node end command_group = init_new_command_group(node) data.each do |key, commands| begin if /^#{key.to_s}$/.match(node.keyed_namespace) commands.each do |c| unless c[:console_command] = "Registry method is missing key 'console_command'." += "\n\n#{c.inspect}" raise Bcome::Exception::InvalidRegistryDataConfig.new end # Verify that the proposed user registered method does not conflict with either an existing method name, instance var, or other registry command name for this node if node.is_node_level_method?(c[:console_command]) || command_group.console_method_name_exists?(c[:console_command]) raise Bcome::Exception::MethodNameConflictInRegistry, "'#{c[:console_command]}'" end command_group << ::Bcome::Registry::Command::Base.new_from_raw_command(c) unless restrict_config?(node, c) ::Bcome::Registry::CommandList.instance.register(node, c[:console_command].to_sym) end end rescue RegexpError => e raise Bcome::Exception::InvalidRegexpMatcherInRegistry, e. end end ::Bcome::Registry::CommandList.instance.add_group_for_node(node, command_group) end |