fancy-open-struct 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -3
- data/Rakefile +1 -16
- data/lib/fancy-open-struct.rb +8 -2
- data/spec/fancy_open_struct_spec.rb +2 -1
- data/spec/spec_helper.rb +11 -11
- metadata +1 -1
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -7,21 +7,6 @@ require 'rspec/core/rake_task'
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
8
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
9
9
|
end
|
10
|
-
namespace :spec do
|
11
|
-
if RUBY_VERSION =~ /^1\.8/
|
12
|
-
desc "Rspec code coverage (1.8.7)"
|
13
|
-
RSpec::Core::RakeTask.new(:coverage) do |spec|
|
14
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
15
|
-
spec.rcov = true
|
16
|
-
end
|
17
|
-
else
|
18
|
-
desc "Rspec code coverage (1.9+)"
|
19
|
-
task :coverage do
|
20
|
-
ENV['COVERAGE'] = 'true'
|
21
|
-
Rake::Task["spec"].execute
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
10
|
|
26
11
|
require 'rdoc/task'
|
27
12
|
Rake::RDocTask.new do |rdoc|
|
@@ -39,7 +24,7 @@ task :fix_permissions do
|
|
39
24
|
File.umask 0022
|
40
25
|
filelist = `git ls-files`.split("\n")
|
41
26
|
FileUtils.chmod 0644, filelist, :verbose => true
|
42
|
-
FileUtils.chmod 0755, ['lib','spec'], :verbose => true
|
27
|
+
FileUtils.chmod 0755, ['lib', 'spec'], :verbose => true
|
43
28
|
end
|
44
29
|
|
45
30
|
task :build => :fix_permissions
|
data/lib/fancy-open-struct.rb
CHANGED
@@ -2,11 +2,11 @@ require 'ostruct'
|
|
2
2
|
require 'forwardable'
|
3
3
|
|
4
4
|
class FancyOpenStruct < OpenStruct
|
5
|
-
VERSION = "0.1.
|
5
|
+
VERSION = "0.1.4"
|
6
6
|
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
hash_methods = Hash.instance_methods(false) - (Hash.instance_methods(false) & OpenStruct.instance_methods(false))
|
9
|
+
hash_methods = Hash.instance_methods(false) - (Hash.instance_methods(false) & OpenStruct.instance_methods(false)) - [:[], :[]=]
|
10
10
|
def_delegators :@table, *hash_methods
|
11
11
|
|
12
12
|
def initialize(hash=nil, args={})
|
@@ -100,6 +100,12 @@ class FancyOpenStruct < OpenStruct
|
|
100
100
|
true
|
101
101
|
end
|
102
102
|
|
103
|
+
def [](*args)
|
104
|
+
len = args.length
|
105
|
+
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1) if len != 1
|
106
|
+
@table[args[0].to_sym]
|
107
|
+
end
|
108
|
+
|
103
109
|
def []=(*args)
|
104
110
|
len = args.length
|
105
111
|
raise ArgumentError, "wrong number of arguments (#{len} for 2)", caller(1) if len != 2
|
@@ -65,9 +65,10 @@ describe FancyOpenStruct do
|
|
65
65
|
it 'converts string hash keys to symbols' do
|
66
66
|
fos = FancyOpenStruct.new
|
67
67
|
fos['blah'] = "John Smith"
|
68
|
-
fos['blah'].should ==
|
68
|
+
fos['blah'].should == "John Smith"
|
69
69
|
fos[:blah].should == "John Smith"
|
70
70
|
fos.blah.should == "John Smith"
|
71
|
+
fos.to_h['blah'].should == nil
|
71
72
|
end
|
72
73
|
|
73
74
|
it 'forwards all of the basic Hash methods directly to the @table instance variable' do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,20 +3,20 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
require 'coveralls'
|
6
|
+
require 'simplecov'
|
7
|
+
require 'coveralls'
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
Coveralls.wear!
|
10
|
+
|
11
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
12
|
+
SimpleCov::Formatter::HTMLFormatter,
|
13
|
+
Coveralls::SimpleCov::Formatter
|
14
|
+
]
|
15
|
+
SimpleCov.start
|
16
16
|
|
17
|
-
# Requires supporting files with custom matchers and
|
17
|
+
# Requires supporting files with custom matchers and macros, etc,
|
18
18
|
# in ./support/ and its subdirectories.
|
19
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
19
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
20
20
|
|
21
21
|
RSpec.configure do |config|
|
22
22
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|