superstruct 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 633c9e438ca5dcc9e25d4a0627b06943649a31c7
4
+ data.tar.gz: 18b3f4b3be03d2dee3b4300d6f959bbf3c9aa1f2
5
+ SHA512:
6
+ metadata.gz: 7e2b9bb82acc5df0f233c5187643d89aed5a1663a607dc541f04d6e8fd6b3f657de82e00ba72412c2d8b708808e36c606e22f8ee24eadb37cc52ba8343473993
7
+ data.tar.gz: c411d80d981cc763331c1e548abe3f4b4ed083c84ab6840a112e5970c1a42f62a08a0cbdae239411b30241d44154566305084f37cadc80094b16ea55b4481514
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in superstruct.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Martin Schmidt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # SuperStruct
2
+
3
+ SuperStruct overwrites the standard {Struct} initializer to add the ability to
4
+ create an instance from a {Hash} of parameters.
5
+
6
+ Compared with the original version, it provides the following additional
7
+ features:
8
+ * ability to initialize an instance from Hash
9
+ * ability to pass a block on creation
10
+
11
+ SuperStruct was written by Simone Carletti for [whois](https://github.com/weppos/whois)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'superstruct'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install superstruct
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ class Band < SuperStruct.new(:name, :genre)
33
+ end
34
+ Band.new({name: 'The Beatles', genre: 'Rock'})
35
+ # => #<struct Band name="The Beatles", genre="Rock">
36
+ ```
37
+ ```ruby
38
+ @overload initialize({ Symbol => Object })
39
+ Initializes the object with a key/value hash.
40
+ @param [{ Symbol => Object }] values
41
+ @return [SuperStruct]
42
+ @overload initialize([ value1, value1, ... ])
43
+ Initializes the object with given values.
44
+ @param [Array] values
45
+ @return [SuperStruct]
46
+ @overload initialize(value1, value1, ...)
47
+ Initializes the object with given values.
48
+ @return [SuperStruct]
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at
60
+ https://github.com/martin-schmidt/superstruct.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "superstruct"
5
+ require 'awesome_print'
6
+ require 'pry'
7
+
8
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,52 @@
1
+ require 'superstruct/version'
2
+ require 'ostruct'
3
+
4
+ # SuperStruct is an enhanced version of the Ruby Standard library {Struct}.
5
+ #
6
+ # Compared with the original version, it provides the following additional features:
7
+ # * ability to initialize an instance from Hash
8
+ # * ability to pass a block on creation
9
+ #
10
+ class SuperStruct < Struct
11
+
12
+ # Overwrites the standard {Struct} initializer
13
+ # to add the ability to create an instance from a {Hash} of parameters.
14
+ #
15
+ # @overload initialize({ Symbol => Object })
16
+ # Initializes the object with a key/value hash.
17
+ # @param [{ Symbol => Object }] values
18
+ # @return [SuperStruct]
19
+ # @overload initialize([ value1, value1, ... ])
20
+ # Initializes the object with given values.
21
+ # @param [Array] values
22
+ # @return [SuperStruct]
23
+ # @overload initialize(value1, value1, ...)
24
+ # Initializes the object with given values.
25
+ # @return [SuperStruct]
26
+ #
27
+ # @yield self
28
+ #
29
+ # @example
30
+ # attributes = { :foo => 1, :bar => "baz" }
31
+ # Struct.new(attributes)
32
+ # # => #<Struct foo=1, bar="baz">
33
+ #
34
+ def initialize(*args)
35
+ if args.first.is_a? Hash
36
+ initialize_with_hash(args.first)
37
+ elsif args.size == 0
38
+ super
39
+ else
40
+ raise ArgumentError
41
+ end
42
+ yield(self) if block_given?
43
+ end
44
+
45
+ private
46
+
47
+ def initialize_with_hash(attributes = {})
48
+ attributes.each do |key, value|
49
+ self[key] = value
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Superstruct
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'superstruct/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "superstruct"
8
+ spec.version = Superstruct::VERSION
9
+ spec.authors = ["Martin Schmidt"]
10
+ spec.email = ["martin.schmidt@bk.ru"]
11
+
12
+ spec.summary = "SuperStruct is an enhanced version of the Ruby Standard library {Struct}."
13
+ spec.description = [
14
+ 'Compared with the original version, it provides the following additional features:',
15
+ ' * ability to initialize an instance from Hash',
16
+ ' * ability to pass a block on creation',
17
+ 'It\'s taken from Simone Carletti\'s whois: https://github.com/weppos/whois and has been put into this gem.'
18
+ ].join("\n") + "\n"
19
+ spec.homepage = "https://github.com/martin-schmidt/superstruct"
20
+ spec.license = "MIT"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.10'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'simplecov'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'awesome_print'
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superstruct
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Schmidt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |
98
+ Compared with the original version, it provides the following additional features:
99
+ * ability to initialize an instance from Hash
100
+ * ability to pass a block on creation
101
+ It's taken from Simone Carletti's whois: https://github.com/weppos/whois and has been put into this gem.
102
+ email:
103
+ - martin.schmidt@bk.ru
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - ".rspec"
110
+ - ".travis.yml"
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - lib/superstruct.rb
118
+ - lib/superstruct/version.rb
119
+ - superstruct.gemspec
120
+ homepage: https://github.com/martin-schmidt/superstruct
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: SuperStruct is an enhanced version of the Ruby Standard library {Struct}.
144
+ test_files: []