Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always override respond_to_missing when overriding method_missing #23

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a27b4ff
tests pass using bundler, once yaml and multi_json are properly required
kornypoet Aug 21, 2013
f1dccc1
fixing conditional single letter flag logic
kornypoet Aug 21, 2013
7216ac8
no path manipulation necessary to require spec_helper
kornypoet Aug 21, 2013
fda2f25
use subject block for testing over before block with instance variabl…
kornypoet Aug 21, 2013
02b8de1
cleaner reading variables
kornypoet Aug 21, 2013
7b7a2a0
never make assertions in a before or after block
kornypoet Aug 21, 2013
64a1467
use subject block for testing over before block with instance variabl…
kornypoet Aug 21, 2013
67c18dc
use doubles instead of instance local instance variables
kornypoet Aug 21, 2013
afd1cc1
use subject block for testing over before block with instance variabl…
kornypoet Aug 21, 2013
5debd29
spacing and naming
kornypoet Aug 21, 2013
3e927f7
wording and spacing
kornypoet Aug 22, 2013
9ea6431
formatting
kornypoet Aug 22, 2013
03c84bd
spacing
kornypoet Aug 22, 2013
4c40658
spacing; use expect:to over lambda:should
kornypoet Aug 22, 2013
dae4753
formatting; use subject over befor block with instance variables; con…
kornypoet Aug 22, 2013
c8b0a1c
use context over describe
kornypoet Aug 22, 2013
4d7cf1b
formatting; use subject over befor block with instance variables
kornypoet Aug 22, 2013
af8a9f3
formatting; context instead of describe
kornypoet Aug 22, 2013
a6f64f7
formatting; use subject over befor block with instance variables; con…
kornypoet Aug 22, 2013
e9e9f84
formatting; use subject over befor block with instance variables; con…
kornypoet Aug 22, 2013
e57e765
context instead of describe
kornypoet Aug 22, 2013
a3eda5f
formatting; use subject over befor block with instance variables; con…
kornypoet Aug 22, 2013
1b8c3b9
context instead of describe
kornypoet Aug 22, 2013
6ae7a4d
added respond_to_missing override with documentation
kornypoet Nov 15, 2013
8522b77
specs for new respond_to_missing override
kornypoet Nov 15, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ For an extensive usage in production, see the "wukong gem.":http://github.com/mr

h2. Notice

Configliere 4.x now has 100% spec coverage, more powerful commandline handling, zero required dependencies. However, it also strips out several obscure features and much magical code, which breaks said obscure features and magic-dependent code. See the "CHANGELOG.":CHANGELOG.textile for details as you upgrade.
Configliere 4.x now has 100% spec coverage, more powerful commandline handling, and minimal required dependencies. However, it also strips out several obscure features and much magical code, which breaks said obscure features and magic-dependent code. See the "CHANGELOG.":CHANGELOG.textile for details as you upgrade.

h2. Design goals:

Expand Down
4 changes: 4 additions & 0 deletions lib/configliere.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'date' # type conversion
require 'time' # type conversion
require 'fileutils' # so save! can mkdir

require 'multi_json'
require 'yaml'

require 'configliere/deep_hash' # magic hash for params
require 'configliere/param' # params container
require 'configliere/define' # define param behavior
Expand Down
4 changes: 2 additions & 2 deletions lib/configliere/commandline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def process_argv!
# -a val
when arg =~ /\A-(\w)\z/
flag = find_param_for_flag($1)
unless flag then @unknown_argvs << flag ; next ; end
unless flag then @unknown_argvs << $1 ; next ; end
if (not args.empty?) && (args.first !~ /\A-/)
val = args.shift
else
Expand All @@ -80,7 +80,7 @@ def process_argv!
# -a=val
when arg =~ /\A-(\w)=(.*)\z/
flag, val = [find_param_for_flag($1), $2]
unless flag then @unknown_argvs << flag ; next ; end
unless flag then @unknown_argvs << $1 ; next ; end
self[flag] = parse_value(val)
else
self.rest << arg
Expand Down
5 changes: 0 additions & 5 deletions lib/configliere/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def read filename, options={}
end

def read_yaml yaml_str, options={}
require 'yaml'
new_data = YAML.load(yaml_str) || {}
# Extract the :env (production/development/etc)
if options[:env]
Expand All @@ -58,11 +57,7 @@ def read_yaml yaml_str, options={}
self
end

#
# we depend on you to require some sort of JSON
#
def read_json json_str, options={}
require 'multi_json'
new_data = MultiJson.load(json_str) || {}
# Extract the :env (production/development/etc)
if options[:env]
Expand Down
14 changes: 14 additions & 0 deletions lib/configliere/define.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ def method_missing meth, *args
else super ; end
end

# Must override respond_to_missing? whenever overriding method_missing
#
# @example
# Settings.respond_to? :foo
# #=> false
# Settings.define :foo
# Settings.respond_to? :foo
# #=> true
def respond_to_missing?(meth, include_private = false)
meth.to_s =~ /^(\w+)(=)?$/ or return super
name, setter = [$1.to_sym, $2]
has_definition?(name) ? true : super
end

end

# Define is included by default
Expand Down
Loading