mighty_struct 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +19 -0
- data/README.md +39 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/mighty_struct/version.rb +3 -0
- data/lib/mighty_struct.rb +52 -0
- data/mighty_struct.gemspec +23 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dfd5542a312e3597a0683dcf3c301f7a7341a116
|
4
|
+
data.tar.gz: 3a1490d3823b849fbdacb2859d235c428b8249fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b99a0ff4de42ea9b0db8ad47408cd8fd0673af5e242ef2ba41d442658b374c039c7105a3a5c85f3d6c6565423ccb49862155c7799f6317e1274a3f8655c4683a
|
7
|
+
data.tar.gz: 3d8c64d0ac78f96d9481bc75d55819ec237b580835aa68875fe9121409a44c0c69dac7e28b3160e9ca9617aca94dc4e40e3fdee4a88985ebdd68344708ae7f14
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in your gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
if !ENV["CI"]
|
7
|
+
group :development do
|
8
|
+
gem "hashdiff"
|
9
|
+
gem "pry", "~> 0.9.12.6"
|
10
|
+
gem "pry-byebug", "<= 1.3.2"
|
11
|
+
gem "pry-rescue", "~> 1.4.1", github: "ConradIrwin/pry-rescue", branch: :master
|
12
|
+
gem "pry-stack_explorer", "~> 0.4.9.1"
|
13
|
+
gem "pry-syntax-hacks", "~> 0.0.6"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
group :test do
|
18
|
+
gem "codeclimate-test-reporter", require: nil
|
19
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# MightyStruct
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mighty_struct`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'mighty_struct'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install mighty_struct
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/mighty_struct/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
task :benchmark do
|
9
|
+
require_relative "./benchmark/joffrey/mab_document"
|
10
|
+
require_relative "./benchmark/joffrey/mab_xml_parser"
|
11
|
+
|
12
|
+
#Benchmark::Joffrey::MabDocument.new.call
|
13
|
+
Benchmark::Joffrey::MabXmlParser.new.call
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mighty_struct"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "mighty_struct/version"
|
2
|
+
|
3
|
+
class MightyStruct
|
4
|
+
def self.define_property_accessors!(mighty_struct, object)
|
5
|
+
if object.is_a?(Hash)
|
6
|
+
object.keys.each do |_key|
|
7
|
+
class_eval <<-EORUBY, __FILE__, __LINE__ + 1
|
8
|
+
def #{_key}
|
9
|
+
value = @object[#{_key.is_a?(Symbol) ? ':' << _key.to_s : _key}]
|
10
|
+
self.class.new?(value) ? self.class.new(value) : value
|
11
|
+
end
|
12
|
+
EORUBY
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.new?(object)
|
18
|
+
object.is_a?(Array) || object.is_a?(Hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(object)
|
22
|
+
unless self.class.new?(object)
|
23
|
+
raise ArgumentError.new("Cannot create a an instance of #{self.class} for the given object!")
|
24
|
+
end
|
25
|
+
|
26
|
+
self.class.define_property_accessors!(self, @object = object)
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](key)
|
30
|
+
# ensure indifferent access
|
31
|
+
if @object.is_a?(Hash)
|
32
|
+
@object[key] || @object[key.to_s] || @object[key.to_sym]
|
33
|
+
else
|
34
|
+
@object[key]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# last line of defense
|
40
|
+
#
|
41
|
+
def method_missing(method_name, *arguments, &block)
|
42
|
+
if @object.respond_to?(method_name)
|
43
|
+
@object.send(method_name, *arguments, &block)
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def respond_to_missing?(method_name, include_private = false)
|
50
|
+
@object.respond_to?(method_name) || super
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mighty_struct/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mighty_struct"
|
8
|
+
spec.version = MightyStruct::VERSION
|
9
|
+
spec.authors = ["Michael Sievers"]
|
10
|
+
spec.summary = %q{A mighty struct which combines OpenStruct like method access with reasonable performance.}
|
11
|
+
spec.homepage = "https://github.com/msievers/mighty_struct"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
14
|
+
spec.bindir = "exe"
|
15
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "benchmark-ips"
|
19
|
+
spec.add_development_dependency "bundler", ">= 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0.0", "< 4.0.0"
|
22
|
+
spec.add_development_dependency "simplecov", ">= 0.8.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mighty_struct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Sievers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: benchmark-ips
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 4.0.0
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 3.0.0
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 4.0.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.8.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.8.0
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- ".gitignore"
|
96
|
+
- ".rspec"
|
97
|
+
- ".travis.yml"
|
98
|
+
- Gemfile
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- lib/mighty_struct.rb
|
104
|
+
- lib/mighty_struct/version.rb
|
105
|
+
- mighty_struct.gemspec
|
106
|
+
homepage: https://github.com/msievers/mighty_struct
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A mighty struct which combines OpenStruct like method access with reasonable
|
129
|
+
performance.
|
130
|
+
test_files: []
|