easy_settings 0.0.1 → 0.0.2
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 +4 -4
- data/easy_settings.gemspec +2 -2
- data/lib/easy_settings.rb +39 -29
- data/lib/easy_settings_version.rb +3 -0
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5e7a4cd755414c8b9ac73537415a9354c216cfbe
         | 
| 4 | 
            +
              data.tar.gz: bb8c676c3225d497595cc0524566c268e97fb444
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4e84cede6e0deb01912732e031d493cba0fb2f33cbfc45d77ee9a36496e20e969fe5d6172780d760599b04e9b47bc77606310b2488fa724a9ede9b904121646f
         | 
| 7 | 
            +
              data.tar.gz: 5c84841fb7e8c092a80ebaac569fbc7c3079e9d960b03a77773941b8baeefee7e6dcdccc47c4e4920a013250d11101270ff57b59f8af2273504227467d03982d
         | 
    
        data/easy_settings.gemspec
    CHANGED
    
    | @@ -1,11 +1,11 @@ | |
| 1 1 | 
             
            # coding: utf-8
         | 
| 2 2 | 
             
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 3 | 
             
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            -
            require " | 
| 4 | 
            +
            require "easy_settings_version"
         | 
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |spec|
         | 
| 7 7 | 
             
              spec.name          = "easy_settings"
         | 
| 8 | 
            -
              spec.version       =  | 
| 8 | 
            +
              spec.version       = EasySettingsVersion::VERSION
         | 
| 9 9 | 
             
              spec.authors       = ["nownabe"]
         | 
| 10 10 | 
             
              spec.email         = ["nownabe@gmail.com"]
         | 
| 11 11 | 
             
              spec.summary       = %q{EasySettings is a simple settings with YAML file.}
         | 
    
        data/lib/easy_settings.rb
    CHANGED
    
    | @@ -2,20 +2,20 @@ require "hashie" | |
| 2 2 | 
             
            require "yaml"
         | 
| 3 3 | 
             
            require "erb"
         | 
| 4 4 |  | 
| 5 | 
            +
            require "easy_settings_version"
         | 
| 6 | 
            +
             | 
| 5 7 | 
             
            class EasySettings < Hashie::Mash
         | 
| 6 | 
            -
               | 
| 8 | 
            +
              include EasySettingsVersion
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              class SourceFileNotExist < StandardError; end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              DEFAULT_FILES = %w(settings.yml config/settings.yml)
         | 
| 7 13 |  | 
| 8 14 | 
             
              class << self
         | 
| 9 15 | 
             
                attr_accessor :source_hash, :source_file, :namespace
         | 
| 10 16 |  | 
| 11 | 
            -
                def method_missing(method_name, *args, &blk)
         | 
| 12 | 
            -
                  p method_name
         | 
| 13 | 
            -
                  p args
         | 
| 14 | 
            -
                  instance.send(method_name, *args, &blk)
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 17 | 
             
                def instance
         | 
| 18 | 
            -
                  @instance ||= new( | 
| 18 | 
            +
                  @instance ||= new(namespace ? _source[namespace] : _source)
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                def load!
         | 
| @@ -27,33 +27,43 @@ class EasySettings < Hashie::Mash | |
| 27 27 | 
             
                  @instance = nil
         | 
| 28 28 | 
             
                  load!
         | 
| 29 29 | 
             
                end
         | 
| 30 | 
            -
              end
         | 
| 31 30 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
                source = load_source_file(source) if source.nil? or source.is_a?(String)
         | 
| 34 | 
            -
                source = source[namespace] if namespace
         | 
| 35 | 
            -
                super(source, default)
         | 
| 36 | 
            -
              end
         | 
| 31 | 
            +
                private
         | 
| 37 32 |  | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 33 | 
            +
                def _source
         | 
| 34 | 
            +
                  return source_hash.to_hash if source_hash
         | 
| 35 | 
            +
                  return _source_from_file if source_file
         | 
| 36 | 
            +
                  _source_from_default_file
         | 
| 37 | 
            +
                end
         | 
| 42 38 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 39 | 
            +
                def _load_file(file)
         | 
| 40 | 
            +
                  content = File.read(file)
         | 
| 41 | 
            +
                  content.empty? ? nil : YAML.load(ERB.new(content).result).to_hash
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def _source_from_file
         | 
| 45 | 
            +
                  unless FileTest.exist?(source_file)
         | 
| 46 | 
            +
                    raise(SourceFileNotExist, "Your source file '#{file}' does not exist.")
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                  _load_file(source_file)
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                def _source_from_default_file
         | 
| 52 | 
            +
                  DEFAULT_FILES.each do |f|
         | 
| 53 | 
            +
                    path = File.expand_path(f, Dir.pwd)
         | 
| 54 | 
            +
                    return _load_file(path) if FileTest.exist?(path)
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                  nil
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def method_missing(method_name, *args, &blk)
         | 
| 60 | 
            +
                  instance.send(method_name, *args, &blk)
         | 
| 48 61 | 
             
                end
         | 
| 49 | 
            -
                nil
         | 
| 50 62 | 
             
              end
         | 
| 51 63 |  | 
| 52 | 
            -
              def  | 
| 53 | 
            -
                 | 
| 54 | 
            -
                 | 
| 55 | 
            -
                content = File.read(file)
         | 
| 56 | 
            -
                content.empty? ? {} : YAML.load(ERB.new(content).result).to_hash
         | 
| 64 | 
            +
              def assign_property(name, value)
         | 
| 65 | 
            +
                super
         | 
| 66 | 
            +
                self[name]
         | 
| 57 67 | 
             
              end
         | 
| 58 68 |  | 
| 59 69 | 
             
              def method_missing(method_name, *args, &blk)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: easy_settings
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - nownabe
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-03- | 
| 11 | 
            +
            date: 2015-03-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: hashie
         | 
| @@ -94,6 +94,7 @@ files: | |
| 94 94 | 
             
            - Rakefile
         | 
| 95 95 | 
             
            - easy_settings.gemspec
         | 
| 96 96 | 
             
            - lib/easy_settings.rb
         | 
| 97 | 
            +
            - lib/easy_settings_version.rb
         | 
| 97 98 | 
             
            homepage: https://github.com/nownabe/easy_settings
         | 
| 98 99 | 
             
            licenses:
         | 
| 99 100 | 
             
            - MIT
         |