hopsoft-fig 0.8.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .idea
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Hopsoft LLC
1
+ Copyright (c) 2009 Nathan Hopkins
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -2,14 +2,13 @@
2
2
 
3
3
  ===DRY up those magic numbers and hard coded strings into something more managable. Fig is the smart way to manage stuff that really belongs in a config file instead of scattered throughout your code.
4
4
 
5
- Here are the Rdocs[http://hopsoft.github.com/fig/README.rdoc.html]
6
- Video tutorial coming soon...
5
+ Read the RDocs[http://hopsoft.github.com/fig/README.rdoc.html] or jump right in with the tutorial video[http://www.screencast.com/t/WwhGvspEy].
7
6
 
8
7
  ==Why
9
8
 
10
9
  Even though Ruby is a dynamic language and hard coded values aren't as big a deal, it's still good practice to have a centralized place to hold certain settings.
11
10
 
12
- In the past I would use a globally available Hash to store this stuff, but have always wanted something more powerful and elegant.
11
+ In the past I used a global Hash to store this stuff, but have always wanted something more powerful and elegant.
13
12
 
14
13
 
15
14
  ==What
@@ -30,7 +29,6 @@ The primary features are:
30
29
  The simplest way to get started is to watch the 10 minute tutorial.
31
30
 
32
31
 
33
-
34
32
  ===Installation
35
33
 
36
34
  Fig is availabe as both a Gem and as a Rails Plugin.
@@ -50,32 +48,26 @@ Second, install the Gem.
50
48
  ===Usage
51
49
  Create a YAML file that will serve as one of the configuration files you plan to use. In a Rails application, I usually create the file config/app.yml, but you can name the file anything you like and can save it to any location within your appliation or library.
52
50
 
53
- Require Fig either explicitly or implicitly. In a Rails application, I generally do this in environment.rb. Note: this step isn't required if you installed as a Rails plugin.
54
- # implicit
55
- require 'hopsoft/fig'
56
- # explicit
57
- gem 'hopsoft-fig'
58
-
59
51
  Instantiate a Fig object that is globally available to your application. In a Rails application, I generally do this in environment.rb.
60
- APP_CONFIG = Hopsoft::Fig.new(RAILS_ROOT + '/config/app.yml')
52
+ CONFIG = Hopsoft::Fig.new(RAILS_ROOT + '/config/app.yml')
61
53
 
62
54
  Start using your settings.
63
- puts APP_CONFIG.settings.message
64
- puts APP_CONFIG.yaml['message']
65
- puts APP_CONFIG.get_setting('message')
55
+ puts CONFIG.settings.message
56
+ puts CONFIG.yaml['message']
57
+ puts CONFIG.get_setting('message')
66
58
 
67
59
  # returns nil instead of an error when the setting doesn't exist
68
- puts APP_CONFIG.get_setting('some.nested.setting.that.may.not.exist')
60
+ puts CONFIG.get_setting('some.nested.setting.that.may.not.exist')
69
61
 
70
62
  Reuse settings in your YAML file (This is a great way to apply the DRY principle to your configuration settings):
71
63
  name: Nathan Hopkins
72
64
  message: Hello from {fig:name}.
73
65
 
74
- puts APP_CONFIG.get_setting('message')
66
+ puts CONFIG.get_setting('message')
75
67
  # outputs -> Hello from Nathan Hopkins.
76
68
 
77
69
  Update the YAML file and load the changes without restarting your application.
78
- APP_CONFIG.load
70
+ CONFIG.load
79
71
 
80
72
 
81
73
  Copyright (c) 2008 Hopsoft LLC, released under the MIT license
data/Rakefile CHANGED
@@ -1,13 +1,55 @@
1
- require 'echoe'
1
+ require 'rubygems'
2
+ require 'rake'
2
3
 
3
- Echoe.new('fig', '0.8.5') do |p|
4
- p.description = "The smart way to manage configuration settings for your Ruby applications."
5
- p.url = "http://github.com/hopsoft/fig"
6
- p.author = "Nathan Hopkins, Hopsoft LLC"
7
- p.email = "natehop@gmail.com"
8
- p.ignore_pattern = ["nbproject*"]
9
- p.development_dependencies = []
10
- puts p.class
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hopsoft-fig"
8
+ gem.summary = "Easy & powerful configuration utility"
9
+ gem.description = <<-DESC
10
+ Easy & powerful configuration for your Ruby applications.
11
+ Similar to settingslogic with a slightly different approach and a few more features.
12
+ DESC
13
+ gem.email = "natehop@gmail.com"
14
+ gem.homepage = "http://github.com/hopsoft/fig"
15
+ gem.authors = ["Nathan Hopkins"]
16
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
11
21
  end
12
22
 
13
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each {|file| load file}
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "fig #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -1,11 +1,11 @@
1
1
  require 'yaml'
2
2
  require 'ostruct'
3
3
  require 'thread'
4
- require File.dirname(__FILE__) + '/../string'
4
+ require File.join(File.dirname(__FILE__), 'string')
5
5
 
6
6
  module Hopsoft
7
7
  class Fig
8
-
8
+
9
9
  # Constructor...
10
10
  #
11
11
  # ====Params
@@ -97,18 +97,18 @@ module Hopsoft
97
97
  pattern = /\{fig:/i
98
98
  start = value.index(pattern, 0)
99
99
  replace = {}
100
-
100
+
101
101
  while start
102
102
  finish = value.index(/\}/, start)
103
103
  key = value[(start + 1)..(finish - 1)]
104
104
  replace[key] = eval("yaml['#{key.sub(/^fig:/i, "").gsub(/\./, "']['")}'].to_s")
105
105
  start = value.index(pattern, finish)
106
106
  end
107
-
107
+
108
108
  value.interpolate(replace, true)
109
109
  end
110
110
  end
111
-
111
+
112
112
  # Recursively adds a hash to an OpenStruct object, ultimately creating a complete OpenStruct object with attributes
113
113
  # for all key/value pairs in the Hash.
114
114
  #
@@ -127,6 +127,6 @@ module Hopsoft
127
127
  end
128
128
  end
129
129
  end
130
-
130
+
131
131
  end
132
132
  end
File without changes
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'fig2'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -1,9 +1,9 @@
1
1
  require 'test/unit'
2
2
  require 'fileutils'
3
- require File.dirname(__FILE__) + '/../lib/hopsoft/fig'
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'hopsoft', 'fig')
4
4
 
5
5
  class FigTest < Test::Unit::TestCase
6
- @@fig = Hopsoft::Fig.new(File.dirname(__FILE__) + '/test.yml')
6
+ @@fig = Hopsoft::Fig.new('test.yml')
7
7
 
8
8
  def test_yaml_values
9
9
  assert @@fig.yaml
@@ -49,11 +49,15 @@ class FigTest < Test::Unit::TestCase
49
49
  assert @@fig.get_setting('some.complete.garbage') == nil
50
50
  end
51
51
 
52
+ def test_nested_interpolation
53
+ assert_equal 'Hi there Nathan Hopkins', @@fig.get_setting('parent.child.message')
54
+ end
55
+
52
56
  def test_change_and_reload
53
57
  dir_name = File.dirname(__FILE__)
54
- orig_file = dir_name + '/test.yml'
55
- new_file = dir_name + '/test2.yml'
56
- bak_file = dir_name + '/test.yml.bak'
58
+ orig_file = File.join(dir_name, 'test.yml')
59
+ new_file = File.join(dir_name, 'test2.yml')
60
+ bak_file = File.join(dir_name, 'test.yml.bak')
57
61
 
58
62
  # make a backup
59
63
  FileUtils.rm(bak_file) if File.exist?(bak_file)
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/string'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'hopsoft', 'string')
3
3
 
4
4
  class StringTest < Test::Unit::TestCase
5
5
 
metadata CHANGED
@@ -1,55 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hopsoft-fig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Nathan Hopkins, Hopsoft LLC
7
+ - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-18 00:00:00 -07:00
12
+ date: 2009-10-21 00:00:00 -06:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description: The smart way to manage configuration settings for your Ruby applications.
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: " Easy & powerful configuration for your Ruby applications.\n Similar to settingslogic with a slightly different approach and a few more features.\n"
17
26
  email: natehop@gmail.com
18
27
  executables: []
19
28
 
20
29
  extensions: []
21
30
 
22
31
  extra_rdoc_files:
23
- - lib/hopsoft/fig.rb
24
- - lib/string.rb
32
+ - LICENSE
25
33
  - README.rdoc
26
- - tasks/fig_tasks.rake
27
34
  files:
28
- - fig.gemspec
29
- - init.rb
30
- - install.rb
31
- - lib/hopsoft/fig.rb
32
- - lib/string.rb
33
- - Manifest
34
- - MIT-LICENSE
35
- - Rakefile
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
36
38
  - README.rdoc
37
- - tasks/fig_tasks.rake
38
- - test/fig_test.rb
39
- - test/string_test.rb
40
- - test/test.yml
41
- - test/test2.yml
42
- - uninstall.rb
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/hopsoft/fig.rb
42
+ - lib/hopsoft/string.rb
43
+ - test/helper.rb
43
44
  has_rdoc: true
44
45
  homepage: http://github.com/hopsoft/fig
46
+ licenses: []
47
+
45
48
  post_install_message:
46
49
  rdoc_options:
47
- - --line-numbers
48
- - --inline-source
49
- - --title
50
- - Fig
51
- - --main
52
- - README.rdoc
50
+ - --charset=UTF-8
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -62,15 +60,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
60
  requirements:
63
61
  - - ">="
64
62
  - !ruby/object:Gem::Version
65
- version: "1.2"
63
+ version: "0"
66
64
  version:
67
65
  requirements: []
68
66
 
69
- rubyforge_project: fig
70
- rubygems_version: 1.2.0
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
71
69
  signing_key:
72
- specification_version: 2
73
- summary: The smart way to manage configuration settings for your Ruby applications.
70
+ specification_version: 3
71
+ summary: Easy & powerful configuration utility
74
72
  test_files:
75
- - test/fig_test.rb
76
- - test/string_test.rb
73
+ - test/test_fig.rb
74
+ - test/helper.rb
75
+ - test/test_string.rb
@@ -1,32 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{fig}
5
- s.version = "0.8.5"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Nathan Hopkins, Hopsoft LLC"]
9
- s.date = %q{2009-03-18}
10
- s.description = %q{The smart way to manage configuration settings for your Ruby applications.}
11
- s.email = %q{natehop@gmail.com}
12
- s.extra_rdoc_files = ["lib/hopsoft/fig.rb", "lib/string.rb", "README.rdoc", "tasks/fig_tasks.rake"]
13
- s.files = ["fig.gemspec", "init.rb", "install.rb", "lib/hopsoft/fig.rb", "lib/string.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "tasks/fig_tasks.rake", "test/fig_test.rb", "test/string_test.rb", "test/test.yml", "test/test2.yml", "uninstall.rb"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://github.com/hopsoft/fig}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fig", "--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{fig}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %q{The smart way to manage configuration settings for your Ruby applications.}
21
- s.test_files = ["test/fig_test.rb", "test/string_test.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- else
29
- end
30
- else
31
- end
32
- end
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'string'
2
- require 'hopsoft/fig'
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :fig do
3
- # # Task goes here
4
- # end
@@ -1,9 +0,0 @@
1
- name: Nathan Hopkins
2
- message: Hello there {fig:name}
3
- message2: Hello there {fig:name2}
4
- name2: Page Hopkins
5
- list: [a, b, c, d, e, f]
6
- parent:
7
- name: '{fig:name}'
8
- child:
9
- name: Emma Hopkins
@@ -1,9 +0,0 @@
1
- name: Jeff Hopkins
2
- message: Hello there {fig:name}
3
- message2: Hello there {fig:name2}
4
- name2: Marie Hopkins
5
- list: [a, b, c, d, e, f]
6
- parent:
7
- name: '{fig:name}'
8
- child:
9
- name: Nathan Hopkins
@@ -1 +0,0 @@
1
- # Uninstall hook code here