keyword_init 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 018ffb118d8fdf0ffb546b8521f8f6b27e34c87e
4
+ data.tar.gz: 73f5d005d2a422553405a0cc882520e5633592d2
5
+ SHA512:
6
+ metadata.gz: 52398c7af6ce1dbca0588c7879af0bb7af5b8e1c60206f55b3d80a7118d5c951c44553c901df304553ea0138369a603eb5269eda2d74be07c4a5b21e84591bba
7
+ data.tar.gz: fc00638b5347138a327e17c8a160a108c25a9828295aa42cde62e82c2c06ca1208e84e9023382d4653d88980a2eafdf54aa2ce0be96930755da8ad927117212d
data/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+ .idea
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+ .bundle
14
+ .config
15
+ .yardoc
16
+ Gemfile.lock
17
+ InstalledFiles
18
+ _yardoc
19
+ coverage
20
+ doc/
21
+ lib/bundler/man
22
+ pkg
23
+ rdoc
24
+ spec/reports
25
+ test/tmp
26
+ test/version_tmp
27
+ tmp
28
+ *.bundle
29
+ *.so
30
+ *.o
31
+ *.a
32
+ mkmf.log
33
+
34
+
35
+ ## Specific to RubyMotion:
36
+ .dat*
37
+ .repl_history
38
+ build/
39
+
40
+ ## Documentation cache and generated files:
41
+ /.yardoc/
42
+ /_yardoc/
43
+ /doc/
44
+ /rdoc/
45
+
46
+ ## Environment normalisation:
47
+ /.bundle/
48
+ /lib/bundler/man/
49
+
50
+ # for a library or gem, you might want to ignore these files since the code is
51
+ # intended to run in multiple environments; otherwise, check them in:
52
+ # Gemfile.lock
53
+ # .ruby-version
54
+ # .ruby-gemset
55
+
56
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
57
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 2.1.1
6
+
7
+ addons:
8
+ code_climate:
9
+ repo_token: 9d7b49edac4909edf2e78624b9c0589e15bf2573e5fc2c3d9e79f4994ffcc411
10
+
11
+ script: 'bundle exec rake spec'
12
+
13
+ notifications:
14
+ email:
15
+ recipients:
16
+ - eturino@eturino.com
17
+ on_failure: change
18
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in keyword_init.gemspec
4
+ gemspec
5
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eduardo Turiño
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,65 @@
1
+ # KeywordInit
2
+
3
+ Gem that provides a keyword argument based `initialize` method to a class, executing the setter of all the recognised keywords.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/keyword_init.svg)](http://badge.fury.io/rb/keyword_init)
6
+ [![Build Status](https://travis-ci.org/eturino/keyword_init.svg?branch=master)](https://travis-ci.org/eturino/keyword_init)
7
+ [![Code Climate](https://codeclimate.com/github/eturino/keyword_init.png)](https://codeclimate.com/github/eturino/keyword_init)
8
+ [![Code Climate Coverage](https://codeclimate.com/github/eturino/keyword_init/coverage.png)](https://codeclimate.com/github/eturino/keyword_init)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'keyword_init'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install keyword_init
23
+
24
+ ## Usage
25
+
26
+ You can have the basic keyword initialization in your class, by including the `KeywordInit` module in your class. This will include the `initialize` method in the class.
27
+
28
+ For each keyword that the `initialize` method receives, it will execute the setter if that method exists (it will look for a method called `keyword_name=`).
29
+
30
+ It will ignore all keywords that don't have a valid setter.
31
+
32
+ ```ruby
33
+ class TestKlass
34
+ include KeywordInit
35
+
36
+ attr_accessor :attrib
37
+ attr_writer :writeonly
38
+ attr_reader :readonly
39
+
40
+ def my_data
41
+ {attrib: attrib, writeonly: writeonly, readonly: readonly}
42
+ end
43
+ end
44
+
45
+ o = TestKlass.new attrib: 1, writeonly: 2, readonly: 3
46
+ x.attrib # => 1
47
+
48
+ # did not set the value because there are no `readonly=` method
49
+ x.readonly # => nil
50
+
51
+ x.my_data # => {attrib: 1, writeonly: 2, readonly: nil}
52
+ ```
53
+
54
+ ## TODO
55
+
56
+ 1. "strict" to raise an error if an unrecognised option is called on method creation (keyword without a setter)
57
+ 2. "direct" integration with `fluent_accessors` ?
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/keyword_init/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color']
8
+ end
9
+
10
+ task :default => :spec
11
+
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'keyword_init/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "keyword_init"
8
+ spec.version = KeywordInit::VERSION
9
+ spec.authors = ["Eduardo Turiño"]
10
+ spec.email = ["eturino@eturino.com"]
11
+ spec.summary = %q{Gem that provides a keyword argument based initialize method to a class, executing the setter of all the recognised keywords.}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rspec-nc"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "pry-nav"
27
+ spec.add_development_dependency "pry-rescue"
28
+ spec.add_development_dependency "pry-stack_explorer"
29
+ spec.add_development_dependency "pry-doc"
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module KeywordInit
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,10 @@
1
+ require "keyword_init/version"
2
+
3
+ module KeywordInit
4
+ def initialize(** properties)
5
+ properties.each do |k, v|
6
+ normal_setter = "#{k}="
7
+ send normal_setter, v if respond_to? normal_setter
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe KeywordInit do
4
+ class TestKlass
5
+ include KeywordInit
6
+
7
+ attr_accessor :attrib
8
+ attr_writer :writeonly
9
+ attr_reader :readonly
10
+
11
+ def my_data
12
+ {attrib: attrib, writeonly: writeonly, readonly: readonly}
13
+ end
14
+ end
15
+
16
+ context 'initialize method' do
17
+ it 'accepts keyword parameters' do
18
+ expect { TestKlass.new attrib: 1, writeonly: 2, readonly: 3 }.not_to raise_error
19
+ end
20
+
21
+ it 'executes the setter of each recognised keyword' do
22
+ expect_any_instance_of(TestKlass).to receive(:attrib=).with(1)
23
+ expect_any_instance_of(TestKlass).to receive(:writeonly=).with(2)
24
+ TestKlass.new attrib: 1, writeonly: 2, readonly: 3
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'codeclimate-test-reporter'
5
+ CodeClimate::TestReporter.start
6
+
7
+ require 'pry'
8
+ require 'keyword_init'
9
+
10
+ RSpec.configure do |config|
11
+ # some (optional) config here
12
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keyword_init
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eduardo Turiño
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-17 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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
+ - !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: rspec-nc
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: pry-nav
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
+ - !ruby/object:Gem::Dependency
98
+ name: pry-rescue
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-doc
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - eturino@eturino.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - keyword_init.gemspec
154
+ - lib/keyword_init.rb
155
+ - lib/keyword_init/version.rb
156
+ - spec/keyword_init_spec.rb
157
+ - spec/spec_helper.rb
158
+ homepage: ''
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.2.2
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Gem that provides a keyword argument based initialize method to a class,
182
+ executing the setter of all the recognised keywords.
183
+ test_files:
184
+ - spec/keyword_init_spec.rb
185
+ - spec/spec_helper.rb
186
+ has_rdoc: