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.
@@ -1,10 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
- - "1.9.2"
5
3
  - "1.9.3"
6
4
  - "2.0.0"
7
- - jruby-18mode # JRuby in 1.8 mode
8
5
  - jruby-19mode # JRuby in 1.9 mode
9
6
  - rbx
10
7
  # uncomment this line if your project needs to run something other than `rake`:
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
@@ -2,11 +2,11 @@ require 'ostruct'
2
2
  require 'forwardable'
3
3
 
4
4
  class FancyOpenStruct < OpenStruct
5
- VERSION = "0.1.3"
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 == nil
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
@@ -3,20 +3,20 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'pry'
5
5
 
6
- if ENV['COVERAGE'] == 'true'
7
- require 'simplecov'
8
- require 'coveralls'
6
+ require 'simplecov'
7
+ require 'coveralls'
9
8
 
10
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
11
- SimpleCov::Formatter::HTMLFormatter,
12
- Coveralls::SimpleCov::Formatter
13
- ]
14
- SimpleCov.start
15
- end
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 macfos, etc,
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy-open-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: