figly 1.0.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 414f612efa27e5aa6f362061fec77f55958b85da
4
+ data.tar.gz: 8ed5ca2a49ff04497a2f0fb07b2ead2d760d1e02
5
+ SHA512:
6
+ metadata.gz: 8744a5d0c0e1e11a188ca326eb19672ff54f5c26e3165e11173022c3b7a992e73ad41be1d504dc12e50356a9f33d2198999e70e61103c511ac6a81e196ac6815
7
+ data.tar.gz: 1ed7f7a1b1aa67326ce4f585e5041158c3aace92ea7dd4b03531792dbd2ba941f3d073c55ddff10242b33e85f687de1be282f8e88fbaf52f8b8b380e8007a9ae
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in figly.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ryan Canty
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Figly
2
+
3
+ A simple config gem to use in either rails or any other ruby gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'figly'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install figly
18
+
19
+ ## Usage
20
+
21
+ The only setup that's required is to set the path of you're configuration file that must be in YAML. Just throw the following code into an initializer:
22
+
23
+ Figly.setup "path/to/config.yml"
24
+
25
+ If you're config looks like this:
26
+
27
+ some_key: 234
28
+ nest1:
29
+ nest2:
30
+ nest3: Yay
31
+
32
+ You can do the following:
33
+
34
+ Figly::Settings.some_key
35
+ #=> 234
36
+
37
+ Figly::Settings.nest1
38
+ #=> {"nest2" => {"nest3" => "Yay"}}
39
+
40
+ Figly::Settings.nest1.nest2.nest3
41
+ #=> "Yay"
42
+
43
+ ## Testing
44
+
45
+ If you want to contribute start by making sure the tests work. Also if you want to isolate the bundled gems to the sandbox (the path below is already in the .gitignore), run:
46
+
47
+ bundle install --path vendor/bundle
48
+
49
+ To access a REPL environment that loads the libraries as well as does the initial setup with the `spec/support/config.yml` set as the path:
50
+
51
+ ./bin/console
52
+
53
+ To run tests:
54
+
55
+ rspec spec
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/onetwopunch/figly/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/bin/sh
2
+ # Run a Ruby REPL.
3
+
4
+ set -e
5
+
6
+ cd $(dirname "$0")/..
7
+ PRY_PATH=$(which pry)
8
+
9
+ if [ -x $PRY_PATH ]
10
+ then
11
+ exec bundle exec ruby $PRY_PATH -Ilib -r figly -r figly/console
12
+ else
13
+ red='\e[0;31m'
14
+ endColor='\e[0m'
15
+ echo -e "${red}Pry was not found or not executable. Make sure `which pry` returns an exacutable.${endColor}"
16
+ fi
data/figly.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'figly/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "figly"
8
+ spec.version = Figly::VERSION
9
+ spec.authors = ["Ryan Canty"]
10
+ spec.email = ["jrcanty@gmail.com"]
11
+ spec.summary = %q{A tiny gem that allows you to access config settings from YAML}
12
+ spec.description = %q{If you ever wanted to access a config Hash using the dot operator, this is the gem for you.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(spec)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rspec"
25
+ end
data/lib/figly.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "figly/version"
2
+ require "figly/settings"
3
+ module Figly
4
+ @@path = nil unless defined? @@path
5
+
6
+ def self.setup(path)
7
+ @@path = path
8
+ end
9
+
10
+ def self.path
11
+ @@path
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require 'pry'
2
+ Pry.config.prompt = lambda do |context, nesting, pry|
3
+ "[figly] #{context}> "
4
+ end
5
+
6
+ config = File.expand_path(File.join(__FILE__, '../../../spec/support/config.yml'))
7
+ Figly.setup config
8
+
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+ module Figly
3
+ module Settings
4
+ module SettingsHash
5
+ def method_missing(meth, *args, &blk)
6
+ m = meth.to_s
7
+ if has_key? m
8
+ value = self[m]
9
+ return value.extend(SettingsHash) if value.instance_of? Hash
10
+ value
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.settings_hash
16
+ YAML.load_file(Figly.path)
17
+ end
18
+
19
+ def self.method_missing(meth, *args, &block)
20
+ if self.settings_hash.has_key? meth.to_s
21
+ val = settings_hash[meth.to_s]
22
+ if val.instance_of?(Hash)
23
+ val.extend(SettingsHash)
24
+ elsif val.instance_of? Array
25
+ val.each_with_index{ |item ,idx| item.extend(SettingsHash) if item.instance_of? Hash }
26
+ end
27
+ return val
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Figly
2
+ VERSION = "1.0.0.beta.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Figly do
4
+ before do
5
+ Figly.setup(config_file)
6
+ end
7
+
8
+ it 'should set path properly' do
9
+ expect(Figly.path).to include('config.yml')
10
+ end
11
+
12
+ it 'should correctly access and integer on the top level' do
13
+ expect(Figly::Settings.some_key).to eq(234)
14
+ end
15
+
16
+ it 'should correctly access an array' do
17
+ expect(Figly::Settings.hello).to eq([1,2,3])
18
+ end
19
+
20
+ it 'should correclty access a hash' do
21
+ expect(Figly::Settings.nest1).to eq({'nest2' => {'nest3' => 'Yay'} } )
22
+ end
23
+
24
+ it 'should correctly access a value nested in a hash' do
25
+ expect(Figly::Settings.nest1.nest2.nest3).to eq('Yay')
26
+ end
27
+
28
+ it 'should correctly access a nestd hash within an array' do
29
+ expect(Figly::Settings.ary.first.nest1.nest2).to eq('Woot')
30
+ end
31
+
32
+ it 'should return nil when accessing a key that doesnt exist' do
33
+ expect(Figly::Settings.blah).to eq(nil)
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,8 @@
1
+ require 'figly'
2
+ require 'support/test_env'
3
+
4
+ RSpec.configure do |config|
5
+ # Use color in STDOUT
6
+ config.color = true
7
+ config.include TestEnv
8
+ end
@@ -0,0 +1,17 @@
1
+
2
+ some_key: 234
3
+ nest1:
4
+ nest2:
5
+ nest3: Yay
6
+
7
+ hello:
8
+ - 1
9
+ - 2
10
+ - 3
11
+
12
+ ary:
13
+ - nest1:
14
+ nest2:
15
+ 'Woot'
16
+ - 3
17
+
@@ -0,0 +1,11 @@
1
+ module TestEnv
2
+ def config_file
3
+ File.join(root, 'spec/support/config.yml')
4
+ end
5
+
6
+ def root
7
+ support = File.dirname __dir__
8
+ File.expand_path(File.join(support, ".."))
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: figly
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Canty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: If you ever wanted to access a config Hash using the dot operator, this
70
+ is the gem for you.
71
+ email:
72
+ - jrcanty@gmail.com
73
+ executables:
74
+ - console
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - figly.gemspec
85
+ - lib/figly.rb
86
+ - lib/figly/console.rb
87
+ - lib/figly/settings.rb
88
+ - lib/figly/version.rb
89
+ - spec/figly_spec.rb
90
+ - spec/spec_helper.rb
91
+ - spec/support/config.yml
92
+ - spec/support/test_env.rb
93
+ homepage: ''
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.1
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A tiny gem that allows you to access config settings from YAML
117
+ test_files:
118
+ - spec/figly_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/support/config.yml
121
+ - spec/support/test_env.rb