bogo-config 0.1.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 +7 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTING.md +25 -0
- data/LICENSE +13 -0
- data/README.md +6 -0
- data/bogo-config.gemspec +18 -0
- data/lib/bogo-config.rb +6 -0
- data/lib/bogo-config/config.rb +117 -0
- data/lib/bogo-config/version.rb +6 -0
- metadata +108 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 1a46c891352700a77e9ef059c11ddab4982b5ad4
         | 
| 4 | 
            +
              data.tar.gz: a55a4a18e70c690a51d78f5cd71a4fbf6ac0dcb7
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: a03fd7ceed2ffbb0a75a8a49c99ec931ce1dcc1cc960142953c6c47d811810e914464efa4392921acd8e21f8ad851a68e394d324d150ef2870cb720cdeb67628
         | 
| 7 | 
            +
              data.tar.gz: e5ae238374429a9c21c74b5ff6c6ad5670bf637ffea2c3a822d54efb6e326a828ce6d741299d019149e507e3474e729638e30b4ae751ca2a267f89fcceba30a8
         | 
    
        data/CHANGELOG.md
    ADDED
    
    
    
        data/CONTRIBUTING.md
    ADDED
    
    | @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            # Contributing
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## Branches
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ### `master` branch
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            The master branch is the current stable released version.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ### `develop` branch
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The develop branch is the current edge of development.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## Pull requests
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * https://github.com/spox/bogo-config/pulls
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Please base all pull requests of the `develop` branch. Merges to
         | 
| 18 | 
            +
            `master` only occur through the `develop` branch. Pull requests
         | 
| 19 | 
            +
            based on `master` will likely be cherry picked.
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## Issues
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            Need to report an issue? Use the github issues:
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            * https://github.com/spox/bogo-config/issues
         | 
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,13 @@ | |
| 1 | 
            +
               Copyright 2014 Chris Roberts
         | 
| 2 | 
            +
             | 
| 3 | 
            +
               Licensed under the Apache License, Version 2.0 (the "License");
         | 
| 4 | 
            +
               you may not use this file except in compliance with the License.
         | 
| 5 | 
            +
               You may obtain a copy of the License at
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                 http://www.apache.org/licenses/LICENSE-2.0
         | 
| 8 | 
            +
             | 
| 9 | 
            +
               Unless required by applicable law or agreed to in writing, software
         | 
| 10 | 
            +
               distributed under the License is distributed on an "AS IS" BASIS,
         | 
| 11 | 
            +
               WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         | 
| 12 | 
            +
               See the License for the specific language governing permissions and
         | 
| 13 | 
            +
               limitations under the License.
         | 
    
        data/README.md
    ADDED
    
    
    
        data/bogo-config.gemspec
    ADDED
    
    | @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
         | 
| 2 | 
            +
            require 'bogo-config/version'
         | 
| 3 | 
            +
            Gem::Specification.new do |s|
         | 
| 4 | 
            +
              s.name = 'bogo-config'
         | 
| 5 | 
            +
              s.version = Bogo::Config::VERSION.version
         | 
| 6 | 
            +
              s.summary = 'Configuration helper library'
         | 
| 7 | 
            +
              s.author = 'Chris Roberts'
         | 
| 8 | 
            +
              s.email = 'code@chrisroberts.org'
         | 
| 9 | 
            +
              s.homepage = 'https://github.com/spox/bogo-config'
         | 
| 10 | 
            +
              s.description = 'Configuration helper library'
         | 
| 11 | 
            +
              s.require_path = 'lib'
         | 
| 12 | 
            +
              s.license = 'Apache 2.0'
         | 
| 13 | 
            +
              s.add_dependency 'bogo'
         | 
| 14 | 
            +
              s.add_dependency 'multi_json'
         | 
| 15 | 
            +
              s.add_dependency 'multi_xml'
         | 
| 16 | 
            +
              s.add_dependency 'attribute_struct'
         | 
| 17 | 
            +
              s.files = Dir['lib/**/*'] + %w(bogo-config.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
         | 
| 18 | 
            +
            end
         | 
    
        data/lib/bogo-config.rb
    ADDED
    
    
| @@ -0,0 +1,117 @@ | |
| 1 | 
            +
            require 'yaml'
         | 
| 2 | 
            +
            require 'multi_xml'
         | 
| 3 | 
            +
            require 'multi_json'
         | 
| 4 | 
            +
            require 'attribute_struct'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'bogo-config'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module Bogo
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              class Config
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                include Bogo::Lazy
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                # @return [String] configuration path
         | 
| 15 | 
            +
                attr_reader :path
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # Create new instance
         | 
| 18 | 
            +
                #
         | 
| 19 | 
            +
                # @param path_or_hash [String, Hash] file/directory path or base Hash
         | 
| 20 | 
            +
                # @return [self]
         | 
| 21 | 
            +
                def initialize(path_or_hash=nil)
         | 
| 22 | 
            +
                  if(path_or_hash.is_a?(String))
         | 
| 23 | 
            +
                    super
         | 
| 24 | 
            +
                  else
         | 
| 25 | 
            +
                    @path = path
         | 
| 26 | 
            +
                    load! if path
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                # Load configuration from file(s)
         | 
| 31 | 
            +
                #
         | 
| 32 | 
            +
                # @return [self]
         | 
| 33 | 
            +
                def load!
         | 
| 34 | 
            +
                  if(path)
         | 
| 35 | 
            +
                    if(File.directory?(path))
         | 
| 36 | 
            +
                      conf = Dir.glob(File.join(path, '*')).inject(Smash.new) do |memo, file_path|
         | 
| 37 | 
            +
                        memo.deep_merge(load_file(file_path))
         | 
| 38 | 
            +
                      end
         | 
| 39 | 
            +
                    elsif(File.file?(path))
         | 
| 40 | 
            +
                      conf = load_file(path)
         | 
| 41 | 
            +
                    else
         | 
| 42 | 
            +
                      raise Errno::ENOENT.new path
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                    data.replace(
         | 
| 45 | 
            +
                      self.class.new(
         | 
| 46 | 
            +
                        conf
         | 
| 47 | 
            +
                      ).data
         | 
| 48 | 
            +
                    )
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                  self
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                # Load configuration file
         | 
| 54 | 
            +
                #
         | 
| 55 | 
            +
                # @param file_path [String] path to file
         | 
| 56 | 
            +
                # @return [Smash]
         | 
| 57 | 
            +
                def load_file(file_path)
         | 
| 58 | 
            +
                  case File.extname(file_path)
         | 
| 59 | 
            +
                  when '.yaml', '.yml'
         | 
| 60 | 
            +
                    yaml_load(file_path)
         | 
| 61 | 
            +
                  when '.json'
         | 
| 62 | 
            +
                    json_load(file_path)
         | 
| 63 | 
            +
                  when '.xml'
         | 
| 64 | 
            +
                    xml_load(file_path)
         | 
| 65 | 
            +
                  else
         | 
| 66 | 
            +
                    result = [:struct_load, :json_load, :yaml_load, :xml_load].detect do |loader|
         | 
| 67 | 
            +
                      begin
         | 
| 68 | 
            +
                        send(loader, file_path)
         | 
| 69 | 
            +
                      rescue => e
         | 
| 70 | 
            +
                        nil
         | 
| 71 | 
            +
                      end
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                    unless(result)
         | 
| 74 | 
            +
                      raise "Failed to load configuration from file (#{file_path})"
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
                    result
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                # Read and parse YAML file
         | 
| 81 | 
            +
                #
         | 
| 82 | 
            +
                # @param file_path
         | 
| 83 | 
            +
                # @return [Smash]
         | 
| 84 | 
            +
                def yaml_load(file_path)
         | 
| 85 | 
            +
                  YAML.load(File.read(file_path)).to_smash
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                # Read and parse JSON file
         | 
| 89 | 
            +
                #
         | 
| 90 | 
            +
                # @param file_path
         | 
| 91 | 
            +
                # @return [Smash]
         | 
| 92 | 
            +
                def json_load(file_path)
         | 
| 93 | 
            +
                  MultiJson.load(File.read(file_path)).to_smash
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                # Read and parse XML file
         | 
| 97 | 
            +
                #
         | 
| 98 | 
            +
                # @param file_path
         | 
| 99 | 
            +
                # @return [Smash]
         | 
| 100 | 
            +
                # @note supar ENTERPRISE
         | 
| 101 | 
            +
                def xml_load(file_path)
         | 
| 102 | 
            +
                  MultiXml.parse(File.read(file_path)).to_smash
         | 
| 103 | 
            +
                end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                # Read and parse AttributeStruct file
         | 
| 106 | 
            +
                #
         | 
| 107 | 
            +
                # @param file_path
         | 
| 108 | 
            +
                # @return [Smash]
         | 
| 109 | 
            +
                def struct_load(file_path)
         | 
| 110 | 
            +
                  result = BasicObject.new.instance_eval(
         | 
| 111 | 
            +
                    IO.read(file_path), file_path, 1
         | 
| 112 | 
            +
                  )
         | 
| 113 | 
            +
                  result._dump.to_smash
         | 
| 114 | 
            +
                end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,108 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: bogo-config
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Chris Roberts
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-12-29 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bogo
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: multi_json
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: multi_xml
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: attribute_struct
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            description: Configuration helper library
         | 
| 70 | 
            +
            email: code@chrisroberts.org
         | 
| 71 | 
            +
            executables: []
         | 
| 72 | 
            +
            extensions: []
         | 
| 73 | 
            +
            extra_rdoc_files: []
         | 
| 74 | 
            +
            files:
         | 
| 75 | 
            +
            - CHANGELOG.md
         | 
| 76 | 
            +
            - CONTRIBUTING.md
         | 
| 77 | 
            +
            - LICENSE
         | 
| 78 | 
            +
            - README.md
         | 
| 79 | 
            +
            - bogo-config.gemspec
         | 
| 80 | 
            +
            - lib/bogo-config.rb
         | 
| 81 | 
            +
            - lib/bogo-config/config.rb
         | 
| 82 | 
            +
            - lib/bogo-config/version.rb
         | 
| 83 | 
            +
            homepage: https://github.com/spox/bogo-config
         | 
| 84 | 
            +
            licenses:
         | 
| 85 | 
            +
            - Apache 2.0
         | 
| 86 | 
            +
            metadata: {}
         | 
| 87 | 
            +
            post_install_message: 
         | 
| 88 | 
            +
            rdoc_options: []
         | 
| 89 | 
            +
            require_paths:
         | 
| 90 | 
            +
            - lib
         | 
| 91 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 92 | 
            +
              requirements:
         | 
| 93 | 
            +
              - - ">="
         | 
| 94 | 
            +
                - !ruby/object:Gem::Version
         | 
| 95 | 
            +
                  version: '0'
         | 
| 96 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 97 | 
            +
              requirements:
         | 
| 98 | 
            +
              - - ">="
         | 
| 99 | 
            +
                - !ruby/object:Gem::Version
         | 
| 100 | 
            +
                  version: '0'
         | 
| 101 | 
            +
            requirements: []
         | 
| 102 | 
            +
            rubyforge_project: 
         | 
| 103 | 
            +
            rubygems_version: 2.2.2
         | 
| 104 | 
            +
            signing_key: 
         | 
| 105 | 
            +
            specification_version: 4
         | 
| 106 | 
            +
            summary: Configuration helper library
         | 
| 107 | 
            +
            test_files: []
         | 
| 108 | 
            +
            has_rdoc: 
         |