config_file 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a7df989b172d91b201aab7c4986e269f3c60208
4
+ data.tar.gz: a7cd04dae5d3c92774e2d074fe25e649ac74c23a
5
+ SHA512:
6
+ metadata.gz: f6a8cf0020296e375fa8208c25c3b7cf32d639605d4523ba0c7c1be8a28d17202d6eb80be6fb30028ff8b9acc2fe6dbdadb6fe1148069bab0355f330696a088f
7
+ data.tar.gz: 01fc1df436c9ab2ba8926e9446ca2d9aacb943615554cf86d34b69cd6bc9a251a3a6b610c5d64659e224e53b44cc2775203e406457ba05f38f147e3b94a94919
@@ -15,7 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = ConfigFile::VERSION
17
17
 
18
- gem.add_dependency("blankslate")
19
-
20
18
  gem.add_development_dependency('rspec')
21
19
  end
@@ -2,8 +2,8 @@ require "config_file/version"
2
2
  require 'yaml'
3
3
  require 'pathname'
4
4
  require 'erb'
5
- require 'blankslate'
6
5
 
6
+ require 'config_file/blank_slate'
7
7
  require 'config_file/file'
8
8
  require 'config_file/include'
9
9
 
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
4
+ # All rights reserved.
5
+
6
+ # Permission is granted for use, copying, modification, distribution,
7
+ # and distribution of modified versions of this work as long as the
8
+ # above copyright notice is included.
9
+ # copied from: https://github.com/masover/blankslate
10
+ #++
11
+
12
+ ######################################################################
13
+ # BlankSlate provides an abstract base class with no predefined
14
+ # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
15
+ # BlankSlate is useful as a base class when writing classes that
16
+ # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
17
+ #
18
+ class ConfigFile::BlankSlate
19
+ class << self
20
+
21
+ # Hide the method named +name+ in the BlankSlate class. Don't
22
+ # hide +instance_eval+ or any method beginning with "__".
23
+ def hide(name)
24
+ methods = instance_methods.map(&:to_sym)
25
+ v, $VERBOSE = $VERBOSE, nil
26
+ if methods.include?(name.to_sym) and
27
+ name !~ /^(__|instance_eval)/
28
+ @hidden_methods ||= {}
29
+ @hidden_methods[name.to_sym] = instance_method(name)
30
+ undef_method name
31
+ end
32
+ $VERBOSE = v
33
+ end
34
+
35
+ def find_hidden_method(name)
36
+ @hidden_methods ||= {}
37
+ @hidden_methods[name] || superclass.find_hidden_method(name)
38
+ end
39
+
40
+ # Redefine a previously hidden method so that it may be called on a blank
41
+ # slate object.
42
+ def reveal(name)
43
+ hidden_method = find_hidden_method(name)
44
+ fail "Don't know how to reveal method '#{name}'" unless hidden_method
45
+ define_method(name, hidden_method)
46
+ end
47
+ end
48
+
49
+ instance_methods.each { |m| hide(m) }
50
+ end
51
+
52
+ ######################################################################
53
+ # Since Ruby is very dynamic, methods added to the ancestors of
54
+ # BlankSlate <em>after BlankSlate is defined</em> will show up in the
55
+ # list of available BlankSlate methods. We handle this by defining a
56
+ # hook in the Object and Kernel classes that will hide any method
57
+ # defined after BlankSlate has been loaded.
58
+ #
59
+ module Kernel
60
+ class << self
61
+ alias_method :blank_slate_method_added, :method_added
62
+
63
+ # Detect method additions to Kernel and remove them in the
64
+ # BlankSlate class.
65
+ def method_added(name)
66
+ result = blank_slate_method_added(name)
67
+ return result if self != Kernel
68
+ ConfigFile::BlankSlate.hide(name)
69
+ result
70
+ end
71
+ end
72
+ end
73
+
74
+ ######################################################################
75
+ # Same as above, except in Object.
76
+ #
77
+ class Object
78
+ class << self
79
+ alias_method :blank_slate_method_added, :method_added
80
+
81
+ # Detect method additions to Object and remove them in the
82
+ # BlankSlate class.
83
+ def method_added(name)
84
+ result = blank_slate_method_added(name)
85
+ return result if self != Object
86
+ ConfigFile::BlankSlate.hide(name)
87
+ result
88
+ end
89
+
90
+ def find_hidden_method(name)
91
+ nil
92
+ end
93
+ end
94
+ end
95
+
96
+ ######################################################################
97
+ # Also, modules included into Object need to be scanned and have their
98
+ # instance methods removed from blank slate. In theory, modules
99
+ # included into Kernel would have to be removed as well, but a
100
+ # "feature" of Ruby prevents late includes into modules from being
101
+ # exposed in the first place.
102
+ #
103
+ class Module
104
+ alias blankslate_original_append_features append_features
105
+ def append_features(mod)
106
+ result = blankslate_original_append_features(mod)
107
+ return result if mod != Object
108
+ instance_methods.each do |name|
109
+ ConfigFile::BlankSlate.hide(name)
110
+ end
111
+ result
112
+ end
113
+ end
@@ -16,6 +16,10 @@ module ConfigFile
16
16
  end
17
17
  end
18
18
 
19
+ def inspect
20
+ %Q{#<ConfigFile::File #{::File.basename(@file)} #{__data__}>}
21
+ end
22
+
19
23
  def __data__
20
24
  @data ||= begin
21
25
  d = nil
@@ -27,6 +27,7 @@ module ConfigFile
27
27
 
28
28
  def self.included(receiver)
29
29
  word = receiver.to_s
30
+ # snake case the class name and look for that as the config file
30
31
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
31
32
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
32
33
  word.tr!("-", "_")
@@ -1,3 +1,3 @@
1
1
  module ConfigFile
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,38 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tal Atlas
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-22 00:00:00.000000000Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: blankslate
16
- requirement: &70102003897160 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
- type: :runtime
20
+ type: :development
23
21
  prerelease: false
24
- version_requirements: *70102003897160
25
- - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &70102003896680 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ! '>='
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
26
  version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70102003896680
36
27
  description: Gem for quickly reading from config files
37
28
  email:
38
29
  - me@tal.by
@@ -40,14 +31,15 @@ executables: []
40
31
  extensions: []
41
32
  extra_rdoc_files: []
42
33
  files:
43
- - .gitignore
44
- - .rspec
34
+ - ".gitignore"
35
+ - ".rspec"
45
36
  - Gemfile
46
37
  - LICENSE
47
38
  - README.md
48
39
  - Rakefile
49
40
  - config_file.gemspec
50
41
  - lib/config_file.rb
42
+ - lib/config_file/blank_slate.rb
51
43
  - lib/config_file/file.rb
52
44
  - lib/config_file/include.rb
53
45
  - lib/config_file/version.rb
@@ -58,27 +50,26 @@ files:
58
50
  - spec/spec_helper.rb
59
51
  homepage: http://github.com/talby/config_file
60
52
  licenses: []
53
+ metadata: {}
61
54
  post_install_message:
62
55
  rdoc_options: []
63
56
  require_paths:
64
57
  - lib
65
58
  required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - ">="
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
64
  requirements:
74
- - - ! '>='
65
+ - - ">="
75
66
  - !ruby/object:Gem::Version
76
67
  version: '0'
77
68
  requirements: []
78
69
  rubyforge_project:
79
- rubygems_version: 1.8.10
70
+ rubygems_version: 2.2.2
80
71
  signing_key:
81
- specification_version: 3
72
+ specification_version: 4
82
73
  summary: Gem for quickly reading from config files
83
74
  test_files:
84
75
  - spec/config/base.yml