initialize_with 0.0.1

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: d565f49b16b55b298aee5e08f8f5de74729d6d1c
4
+ data.tar.gz: bdd1c75f7610ab755baefbd672935d57458597dc
5
+ SHA512:
6
+ metadata.gz: c353642083cb2480aa60c10719636715380c8f154474dc1b1e9ea4ddb4b7a94e8cfeeeeb842bfff76043954a45401ad8ad587709b9925159d23e2289ed1f37ea
7
+ data.tar.gz: 7add15606276a34fa59934f91a9dae7efba813c043bae9f69f5baf016093f4fc0c2f539bda549b9d68a091bfb66266a4ab9701d6bb378a6d924c577b0ad42a1f
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.swo
2
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ initialize_with (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.5.1)
10
+ rake (10.4.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ initialize_with!
17
+ minitest (~> 5.5)
18
+ rake (~> 10.2)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michael
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ ## initialize_with
2
+
3
+ ### Install
4
+ ```
5
+ gem install initialize_with
6
+ ```
7
+
8
+ ### Requirements
9
+ ruby version >= 1.9.3
10
+
11
+ ### Synopsis
12
+ ``` ruby
13
+ require 'initialize_with'
14
+
15
+ class Foo
16
+ extend InitializeWith
17
+ initialize_with [:a, :b], c: 1, d: 2
18
+ attr_reader :a, :b, :c, :d
19
+ end
20
+
21
+ foo = Foo.new("foo", "bar")
22
+ print foo.a, foo.b, foo.c, foo.d, "\n" # => "foobar12"
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.libs << 'lib'
6
+ t.ruby_opts << '-rtest_helper'
7
+ t.test_files = FileList['test/test*.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task default: :test
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'initialize_with'
3
+ s.version = '0.0.1'
4
+ s.summary = 'DSL for shorter shorter arguments initialization'
5
+ s.description = 'DSL for shorter shorter arguments initialization'
6
+ s.author = ['Michael Lutsiuk']
7
+ s.email = 'mmaccoffe@gmail.com'
8
+ s.license = 'MIT'
9
+ s.homepage = 'https://github.com/mediaslave24/initialize_with'
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files test/*`.split("\n")
13
+
14
+ s.required_ruby_version = '>= 1.9.3'
15
+
16
+ s.add_development_dependency 'rake', '~> 10.2'
17
+ s.add_development_dependency 'minitest', '~> 5.5'
18
+ end
@@ -0,0 +1,37 @@
1
+ module InitializeWith
2
+ def initialize_with(*args)
3
+ case a = args.shift
4
+ when Array then h = args.pop || {}
5
+ when Hash then h, a = [], h
6
+ end
7
+
8
+ unless a.is_a?(Array) && h.is_a?(Hash)
9
+ raise TypeError,
10
+ "wrong type of arguments for initialize_with" <<
11
+ " expected [Array, Hash], but have [#{a.class}, #{h.class}]"
12
+ end
13
+
14
+ h.reject! { |k,_| a.any? { |name| name.to_s == k.to_s} }
15
+
16
+ required = a.join(', ')
17
+
18
+ optional = h.map do |k, v|
19
+ "#{k} = #{v.to_s}"
20
+ end.join(', ')
21
+
22
+ optional = ", #{optional}" unless optional.empty?
23
+
24
+ assign = (a + h.keys).map do |name|
25
+ "@#{name} = #{name}"
26
+ end.join("\n")
27
+
28
+ class_eval <<-MTD, __FILE__, __LINE__
29
+ def initialize(#{required}#{optional}) # def initialize(a, b, c = 1, d = 2)
30
+ #{assign} # @a = a
31
+ end # @b = b
32
+ # @c = c
33
+ # @d = d
34
+ # end
35
+ MTD
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require
4
+ require 'minitest/autorun'
5
+ require 'minitest/test'
6
+ require 'initialize_with'
@@ -0,0 +1,23 @@
1
+ class TestInitializeWith < Minitest::Test
2
+ class Foo
3
+ extend ::InitializeWith
4
+ initialize_with [:a, :b], c: 1, d: 2, b: 42
5
+ attr_reader :a, :b, :c, :d
6
+ end
7
+
8
+ def setup
9
+ @foo = Foo.new('foo', 'bar')
10
+ end
11
+
12
+ def test_args
13
+ assert_equal(@foo.a, 'foo')
14
+ assert_equal(@foo.b, 'bar')
15
+ assert_equal(@foo.c, 1)
16
+ assert_equal(@foo.d, 2)
17
+ end
18
+
19
+ def test_exception
20
+ assert_raises(ArgumentError) { Foo.new }
21
+ assert_raises(ArgumentError) { Foo.new(1) }
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: initialize_with
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Lutsiuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '5.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '5.5'
41
+ description: DSL for shorter shorter arguments initialization
42
+ email: mmaccoffe@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - initialize_with.gemspec
54
+ - lib/initialize_with.rb
55
+ - test/test_helper.rb
56
+ - test/test_initialize_with.rb
57
+ homepage: https://github.com/mediaslave24/initialize_with
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.9.3
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: DSL for shorter shorter arguments initialization
81
+ test_files:
82
+ - test/test_helper.rb
83
+ - test/test_initialize_with.rb