rails_config_loader 0.1.4 → 0.1.5

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.
data/README.md CHANGED
@@ -14,28 +14,28 @@ module MainApp
14
14
 
15
15
  # load seed file (see geo-autocomplete demo)
16
16
  def seed
17
- @seed ||= load_yaml('config/seed.yml', :dir => 'db')
17
+ @seed ||= load_yml :seed, :dir => 'db')
18
18
  end
19
19
 
20
20
  # config for the app
21
21
  # any missing method on this is delegated to the
22
22
  # Hashie wrapping this loaded content
23
23
  def config
24
- @config ||= load_yaml('app.yml')
24
+ @config ||= load_yml :app
25
25
  end
26
26
 
27
27
  # auto detect load method based on filename extension
28
28
  def app
29
- @app ||= load('app.yml')
29
+ @app ||= load 'app.yml'
30
30
  end
31
31
 
32
- # load json
32
+ # load json content
33
33
  def addresses locale = :da
34
34
  @config ||= load_content '/data/addresses.json', :locale => get_locale(locale)
35
35
  end
36
36
 
37
37
  def payment_provider
38
- @payment_provider ||= load_yaml('payment_gateway/quickpay.yml')
38
+ @payment_provider ||= load_yaml 'payment_gateway/quickpay'
39
39
  end
40
40
  end
41
41
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -5,9 +5,10 @@ module ConfigLoader
5
5
  attr_reader :locale, :path, :file_name, :ext, :file_path, :root
6
6
 
7
7
  # will try root element if such exists
8
- def initialize file_path, options = {}
8
+ def initialize file_path, options = {}
9
9
  @path = File.dirname file_path
10
10
  @file_name = File.basename file_path
11
+
11
12
  name = parts.first.sub(/\.$/, '')
12
13
  @ext = parts.last
13
14
  @locale = options[:locale] unless blank?(options[:locale])
@@ -37,6 +38,14 @@ module ConfigLoader
37
38
 
38
39
  protected
39
40
 
41
+ def parts
42
+ @parts ||= file_name.split(/(#{reg_ext_format})$/)
43
+ end
44
+
45
+ def path? file_path
46
+ file_path.kind_of?(String) && file_path =~ /\.#{reg_ext_format}/
47
+ end
48
+
40
49
  def blank? obj
41
50
  !obj || obj.empty?
42
51
  end
@@ -2,12 +2,17 @@ require 'config_loader/base'
2
2
 
3
3
  module ConfigLoader
4
4
  class Json < Base
5
+ def initialize file_path, options = {}
6
+ file_path = "#{file_path}.json" unless path?(file_path)
7
+ super file_path, options
8
+ end
9
+
5
10
  def content
6
11
  @content ||= JSON.parse file_content.read
7
12
  end
8
13
 
9
- def parts
10
- @parts ||= file_name.split(/(json)$/)
14
+ def reg_ext_format
15
+ 'json'
11
16
  end
12
17
  end
13
18
  end
@@ -2,12 +2,20 @@ require 'config_loader/base'
2
2
 
3
3
  module ConfigLoader
4
4
  class Yaml < Base
5
+ def initialize file_path, options = {}
6
+ default_ext = options[:default_ext] || 'yml'
7
+ file_path = "#{file_path}.#{default_ext}" unless path?(file_path)
8
+ super file_path, options
9
+ end
10
+
5
11
  def content
6
- @content ||= ::YAML::load file_content
12
+ @content ||= ::YAML.load file_content
7
13
  end
8
14
 
9
- def parts
10
- @parts ||= file_name.split(/(ya?ml$)/)
15
+ protected
16
+
17
+ def reg_ext_format
18
+ 'ya?ml'
11
19
  end
12
20
  end
13
21
  end
@@ -23,7 +23,11 @@ module ConfigLoader
23
23
  end
24
24
 
25
25
  def load_yaml file_path, options = {}
26
- ConfigLoader::Yaml.new file_path, options = {}
26
+ ConfigLoader::Yaml.new file_path, options = {:default_ext => :yaml}
27
+ end
28
+
29
+ def load_yml file_path, options = {}
30
+ ConfigLoader::Yaml.new file_path, options = {:default_ext => :yml}
27
31
  end
28
32
 
29
33
  def load_json file_path, options = {}
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rails_config_loader"
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = "2012-05-20"
12
+ s.date = "2012-08-06"
13
13
  s.description = "Load yaml and json config files and \n make the structures easily available for use in the app."
14
14
  s.email = "kmandrup@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "spec/config_loader/yaml_spec.rb",
37
37
  "spec/config_loader_spec.rb",
38
38
  "spec/fixtures/config/app.yml",
39
+ "spec/fixtures/config/enum.json",
39
40
  "spec/fixtures/config/facebook.yml",
40
41
  "spec/fixtures/config/htc.yml",
41
42
  "spec/fixtures/config/payment_gateway/quickpay.da.yml",
@@ -12,13 +12,23 @@ describe ConfigLoader::Json do
12
12
 
13
13
  its(:content) { should_not be_nil }
14
14
  its(:content) { should == [{"number"=>"004", "street"=>"Bøllemosegårdsvej", "city"=>"Øbro", "region"=>"København"}, {"number"=>"001", "street"=>"Bøllemosegårdsvej", "city"=>"Venners", "region"=>"København"}, {"number"=>"002", "street"=>"Havlyngbuen", "city"=>"Amager", "region"=>"København"}, {"number"=>"001", "street"=>"Havlyngbuen", "city"=>"Amager", "region"=>"København"}, {"number"=>"051", "street"=>"Hedegaardsvej", "city"=>"Engdraget", "region"=>"København"}] }
15
- end
16
15
 
17
- describe '.load' do
18
- subject { addresses }
19
- let(:addresses) { MainApp.config.addresses }
16
+ describe 'implicit json' do
17
+ subject { config }
18
+ let(:config) { ConfigLoader::Json.new(:enum) }
19
+
20
+ its(:root) { should == nil }
21
+ specify { subject.as_hash.answer == 'yes' }
22
+ end
23
+
24
+
25
+ describe '.load' do
26
+ subject { addresses }
27
+ let(:addresses) { MainApp.config.addresses }
20
28
 
21
- specify do
22
- addresses.first.should == {"number"=>"004", "street"=>"Bøllemosegårdsvej", "city"=>"Øbro", "region"=>"København"}
29
+ specify do
30
+ addresses.first.should == {"number"=>"004", "street"=>"Bøllemosegårdsvej", "city"=>"Øbro", "region"=>"København"}
31
+ end
23
32
  end
24
33
  end
34
+
@@ -13,6 +13,14 @@ describe ConfigLoader::Yaml do
13
13
 
14
14
  specify { subject.as_hash.domain == 'www.facebook.com' }
15
15
 
16
+ describe 'implicit yml' do
17
+ subject { config }
18
+ let(:config) { ConfigLoader::Yaml.new(:htc) }
19
+
20
+ its(:root) { should == nil }
21
+ specify { subject.as_hash.domain == 'www.htc.com' }
22
+ end
23
+
16
24
  describe 'no root' do
17
25
  subject { config }
18
26
  let(:config) { ConfigLoader::Yaml.new('htc.yml') }
@@ -0,0 +1,3 @@
1
+ {
2
+ "answer": "yes"
3
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_config_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-20 00:00:00.000000000 Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -151,6 +151,7 @@ files:
151
151
  - spec/config_loader/yaml_spec.rb
152
152
  - spec/config_loader_spec.rb
153
153
  - spec/fixtures/config/app.yml
154
+ - spec/fixtures/config/enum.json
154
155
  - spec/fixtures/config/facebook.yml
155
156
  - spec/fixtures/config/htc.yml
156
157
  - spec/fixtures/config/payment_gateway/quickpay.da.yml
@@ -174,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
175
  version: '0'
175
176
  segments:
176
177
  - 0
177
- hash: 889680361015495165
178
+ hash: 1155841106093705541
178
179
  required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  none: false
180
181
  requirements: