smart_init 0.1.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: b7dc87097a9f29e7ec98b46da93f31a0f97b3f78
4
+ data.tar.gz: 3607b757069ec5da39b8dfadee1f3867bbcead68
5
+ SHA512:
6
+ metadata.gz: 37c4bf26508473b50275d6923c8c735cbce63d9680151cc1b47ec33d858c9cf053a4898be359633113fd2f0a77c3223c232a572ddb985aa5fb4f8a74d3766e2e
7
+ data.tar.gz: 233481aee605bee113c8391d7bdf925d96ddd33d0cc4abaceb49f1c2c099fb43ec13bedba3f108c40b0428f2357ff2a558a1839b99214bd8cf29fae9e2732d4a
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ pkg/
4
+ *.gem
5
+ coverage/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 2.2.0
3
+ - 2.3.0
4
+ - 2.3.1
5
+ - 2.4.0
6
+ notifications:
7
+ email: false
8
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 pawurb
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # SmartInit [![Build Status](https://travis-ci.org/pawurb/smart_init.svg)](https://travis-ci.org/pawurb/smart_init)
2
+
3
+ Do you find yourself writing a lot of boilerplate code like this?
4
+
5
+ ``` ruby
6
+ def initialize(network_provider, api_token)
7
+ @network_provider = network_provider
8
+ @api_token = api_token
9
+ end
10
+ ```
11
+
12
+ WIP...
13
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ module SmartInit
2
+ def initialize_with *attributes
3
+ define_method :initialize do |*parameters|
4
+ if attributes.count != parameters.count
5
+ raise ArgumentError, "wrong number of arguments (given #{parameters.count}, expected #{attributes.count})"
6
+ end
7
+
8
+ attributes.zip(parameters).each do |pair|
9
+ name = pair[0]
10
+ value = pair[1]
11
+ instance_variable_set("@#{name}", value)
12
+ end
13
+ end
14
+
15
+ instance_eval do
16
+ private
17
+
18
+ attr_reader *attributes
19
+ end
20
+ end
21
+ end
22
+
23
+ class SmartInit::Base
24
+ extend SmartInit
25
+ end
@@ -0,0 +1,3 @@
1
+ module SmartInit
2
+ VERSION = "0.1.0"
3
+ end
data/lib/smart_init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'smart_init/main'
2
+
3
+ module SmartInit
4
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smart_init/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "smart_init"
8
+ gem.version = SmartInit::VERSION
9
+ gem.authors = ["pawurb"]
10
+ gem.email = ["p.urbanek89@gmail.com"]
11
+ gem.summary = %q{ Remove Ruby initializer boilerplate code }
12
+ gem.description = %q{ A smart DSL for ruby initializers boilerplate }
13
+ gem.homepage = "http://github.com/pawurb/smart_init"
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = gem.files.grep(%r{^(spec)/})
16
+ gem.require_paths = ["lib"]
17
+ gem.license = "MIT"
18
+ gem.add_development_dependency "rake"
19
+ gem.add_development_dependency "test-unit"
20
+ end
@@ -0,0 +1,44 @@
1
+ require "test/unit"
2
+ require 'smart_init'
3
+
4
+ class TestClass
5
+ extend SmartInit
6
+ initialize_with :attribute_1, :attribute_2
7
+ end
8
+
9
+ class SmartInitTest < Test::Unit::TestCase
10
+ def test_number_of_attributes
11
+ assert_nothing_raised do
12
+ TestClass.new(
13
+ "attr_1_value",
14
+ "attr_2_value"
15
+ )
16
+ end
17
+
18
+ assert_raise ArgumentError do
19
+ TestClass.new(
20
+ "attr_1_value"
21
+ )
22
+ end
23
+ end
24
+
25
+ def test_instance_variables
26
+ assert_equal test_object.instance_variable_get("@attribute_1"), "attr_1_value"
27
+ end
28
+
29
+ def test_private_getters
30
+ assert_raise NoMethodError do
31
+ test_object.attribute_1
32
+ end
33
+
34
+ assert_equal test_object.send(:attribute_1), "attr_1_value"
35
+ end
36
+
37
+ private
38
+
39
+ def test_object
40
+ @_test_object ||= TestClass.new("attr_1_value", "attr_2_value")
41
+ end
42
+ end
43
+
44
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_init
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pawurb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-04 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: '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: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: " A smart DSL for ruby initializers boilerplate "
42
+ email:
43
+ - p.urbanek89@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/smart_init.rb
55
+ - lib/smart_init/main.rb
56
+ - lib/smart_init/version.rb
57
+ - smart_init.gemspec
58
+ - test/test_smart_init.rb
59
+ homepage: http://github.com/pawurb/smart_init
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Remove Ruby initializer boilerplate code
83
+ test_files: []