windcharger 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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +9 -0
- data/lib/windcharger.rb +5 -0
- data/lib/windcharger/attributes.rb +19 -0
- data/lib/windcharger/hash_transformer.rb +10 -0
- data/lib/windcharger/version.rb +3 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/windcharger/attributes_spec.rb +55 -0
- data/spec/windcharger/hash_transformer_spec.rb +25 -0
- data/spec/windcharger_spec.rb +0 -0
- data/windcharger.gemspec +24 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c46f7711e884e9414c36dbae526dd1ce280797fa
|
4
|
+
data.tar.gz: 850d9751a2023317625aad78a5dcdb1444e931e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a8cc81462b30354c72ff7e5fb3bc3e9e07a60296dfa18400a9949450f929f2865877ccbb0c12dedebb30d4f97a4aabeba284a09f2b6a417429e408e2159b689
|
7
|
+
data.tar.gz: e9ba620552c61fa1fd61f603434f6ed81896145b8eeaf6a28a1ccc5e745df52a90f8f21e1d66d1fe0c73375c17b831dd6e27bd23f9093a5cec84ce538a2a3ece
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 J. Andrew Marshall <http://johnandrewmarshall.com>
|
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,73 @@
|
|
1
|
+
# Windcharger
|
2
|
+
|
3
|
+
[](https://travis-ci.org/amarshall/windcharger)
|
4
|
+
[](https://codeclimate.com/github/amarshall/windcharger)
|
5
|
+
[](https://rubygems.org/gems/windcharger)
|
6
|
+
|
7
|
+

|
8
|
+
|
9
|
+
Windcharger is a small library to easily make objects that transform input via many methods.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Install as usual: `gem install windcharger` or add `gem 'windcharger'` to your Gemfile.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Declare methods as attributes by extending `Windcharger::Attributes` and preceding methods with `attribute`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class MyTransformer
|
21
|
+
extend Windcharger::Attributes
|
22
|
+
|
23
|
+
attribute
|
24
|
+
def foo; end
|
25
|
+
|
26
|
+
attribute
|
27
|
+
def bar; end
|
28
|
+
|
29
|
+
def not_an_attribute; end
|
30
|
+
end
|
31
|
+
|
32
|
+
MyTransformer.attributes #=> [:foo, :bar]
|
33
|
+
```
|
34
|
+
|
35
|
+
This isn’t very useful on its own, so include `Windcharger::HashTransformer` to get the `transform` method:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class MyTransformer
|
39
|
+
extend Windcharger::Attributes
|
40
|
+
include Windcharger::HashTransformer
|
41
|
+
|
42
|
+
attribute
|
43
|
+
def foo
|
44
|
+
:the_foo
|
45
|
+
end
|
46
|
+
|
47
|
+
attribute
|
48
|
+
def bar
|
49
|
+
:walked_into_a_bar
|
50
|
+
end
|
51
|
+
|
52
|
+
def not_an_attribute
|
53
|
+
42
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
my_transformer = MyTransformer.new
|
58
|
+
my_transformer.transform #=> { :foo => :the_foo, :bar => :walked_into_a_bar }
|
59
|
+
```
|
60
|
+
|
61
|
+
Add an `initialize` that takes some input and then transform it to each attribute in their respective methods and you have a nice transformer object.
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create new Pull Request
|
70
|
+
|
71
|
+
## Credits & License
|
72
|
+
|
73
|
+
Copyright © 2013 J. Andrew Marshall. License is available in the LICENSE file.
|
data/Rakefile
ADDED
data/lib/windcharger.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Windcharger
|
2
|
+
module Attributes
|
3
|
+
def attributes
|
4
|
+
@__attributes || []
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def attribute
|
10
|
+
@__windcharger_next_is_attribute = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_added name
|
14
|
+
return unless @__windcharger_next_is_attribute
|
15
|
+
(@__attributes ||= []) << name
|
16
|
+
@__windcharger_next_is_attribute = false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'windcharger/attributes'
|
3
|
+
|
4
|
+
describe Windcharger::Attributes do
|
5
|
+
it "attributes is an empty array by default" do
|
6
|
+
transformer_class = Class.new { extend Windcharger::Attributes }
|
7
|
+
expect(transformer_class.attributes).to eq []
|
8
|
+
end
|
9
|
+
|
10
|
+
it "attribute is private" do
|
11
|
+
transformer_class = Class.new { extend Windcharger::Attributes }
|
12
|
+
expect { transformer_class.attribute }.to raise_error NoMethodError, /private/
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not add a method not preceded by a call to attribute to the list of attributes" do
|
16
|
+
transformer_class = Class.new do
|
17
|
+
extend Windcharger::Attributes
|
18
|
+
|
19
|
+
def foo; end
|
20
|
+
end
|
21
|
+
expect(transformer_class.attributes).to eq []
|
22
|
+
end
|
23
|
+
|
24
|
+
it "adds a method preceded by a call to attribute to the list of attributes" do
|
25
|
+
transformer_class = Class.new do
|
26
|
+
extend Windcharger::Attributes
|
27
|
+
|
28
|
+
attribute
|
29
|
+
def foo; end
|
30
|
+
end
|
31
|
+
expect(transformer_class.attributes).to eq [:foo]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "appropriately does and does not add multiple methods" do
|
35
|
+
transformer_class = Class.new do
|
36
|
+
extend Windcharger::Attributes
|
37
|
+
|
38
|
+
attribute
|
39
|
+
def foo; end
|
40
|
+
|
41
|
+
def bar; end
|
42
|
+
def baz; end
|
43
|
+
|
44
|
+
attribute
|
45
|
+
def qux; end
|
46
|
+
|
47
|
+
attribute
|
48
|
+
def foobar; end
|
49
|
+
|
50
|
+
def barbaz; end
|
51
|
+
end
|
52
|
+
|
53
|
+
expect(transformer_class.attributes).to eq [:foo, :qux, :foobar]
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'windcharger/hash_transformer'
|
3
|
+
|
4
|
+
describe Windcharger::HashTransformer do
|
5
|
+
describe "#transform" do
|
6
|
+
it "returns a hash with attribute names and return values from those methods" do
|
7
|
+
transformer_class = Class.new do
|
8
|
+
extend Windcharger::Attributes
|
9
|
+
include Windcharger::HashTransformer
|
10
|
+
|
11
|
+
attribute
|
12
|
+
def foo; 42; end
|
13
|
+
attribute
|
14
|
+
def bar; 'colorless green ideas'; end
|
15
|
+
def baz; end
|
16
|
+
end
|
17
|
+
transformer = transformer_class.new
|
18
|
+
|
19
|
+
expect(transformer.transform).to eq({
|
20
|
+
foo: 42,
|
21
|
+
bar: 'colorless green ideas',
|
22
|
+
})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
File without changes
|
data/windcharger.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'windcharger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'windcharger'
|
8
|
+
spec.version = Windcharger::VERSION
|
9
|
+
spec.authors = ['Andrew Marshall']
|
10
|
+
spec.email = ['andrew@johnandrewmarshall.com']
|
11
|
+
spec.description = %q{Small library to easily make objects that transform input via many methods.}
|
12
|
+
spec.summary = %q{Small library to easily make objects that transform input via many methods.}
|
13
|
+
spec.homepage = 'http://johnandrewmarshall.com/projects/windcharger'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: windcharger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Marshall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-20 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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
|
+
description: Small library to easily make objects that transform input via many methods.
|
56
|
+
email:
|
57
|
+
- andrew@johnandrewmarshall.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/windcharger.rb
|
69
|
+
- lib/windcharger/attributes.rb
|
70
|
+
- lib/windcharger/hash_transformer.rb
|
71
|
+
- lib/windcharger/version.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- spec/windcharger/attributes_spec.rb
|
74
|
+
- spec/windcharger/hash_transformer_spec.rb
|
75
|
+
- spec/windcharger_spec.rb
|
76
|
+
- windcharger.gemspec
|
77
|
+
homepage: http://johnandrewmarshall.com/projects/windcharger
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.1.9
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Small library to easily make objects that transform input via many methods.
|
101
|
+
test_files:
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/windcharger/attributes_spec.rb
|
104
|
+
- spec/windcharger/hash_transformer_spec.rb
|
105
|
+
- spec/windcharger_spec.rb
|
106
|
+
has_rdoc:
|