windcharger 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fdff2baf8318e70da114fccb0d575f5769a5fa8
4
- data.tar.gz: f312d08ac3c00f40a0a8051d80f4a6c1ceef22d0
3
+ metadata.gz: a25e071066657d28c05aee00abbf363591adc933
4
+ data.tar.gz: 85e0f55db7a73ddb864c0ad12ddd15afa1b7f26b
5
5
  SHA512:
6
- metadata.gz: 97187df83b10e7b6f50d5680e41e0e5d2778de774502ce90164ba547cb0de8937160849c83a2476bc7de87ef3921a7241326a3bd583fdaccc54e87efbe830124
7
- data.tar.gz: 84ebb7adada52daaaa85abde5429cc3aa05d160195a13394ab7848333520dc34cdcbf1a42f322baa7a06bae9d4a1844f81eacba7715034e87b340f9a692ef22d
6
+ metadata.gz: 6dc1f09246efc3c02b452294a508645bee4d4ed82c5c95b29e8b445b3ff1cb6aeda7d08664373f3f1b5e9fd56fcc3abf76dd3ed0a558651defe7faae499d951a
7
+ data.tar.gz: 80e3fb2d2adcfe3f22500a550842d2be1dd1bf8a5522275374121960ed3b82503e21a90ce9c75f2e2ce7d66eacddf05ecf5137225cd7edb026f6b2397be0496f
data/README.md CHANGED
@@ -53,13 +53,29 @@ class MyTransformer
53
53
  :walked_into_a_bar
54
54
  end
55
55
 
56
+ def qux
57
+ 1
58
+ end
59
+
60
+ attribute :qax, :qux
61
+
62
+ def qax
63
+ 2
64
+ end
65
+
56
66
  def not_an_attribute
57
67
  42
58
68
  end
59
69
  end
60
70
 
61
71
  my_transformer = MyTransformer.new
62
- my_transformer.transform #=> { :foo => :the_foo, :bar => :walked_into_a_bar }
72
+ my_transformer.transform
73
+ #=> {
74
+ # :foo => :the_foo,
75
+ # :bar => :walked_into_a_bar,
76
+ # :qax => 2,
77
+ # :qux => 1,
78
+ # }
63
79
  ```
64
80
 
65
81
  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.
@@ -6,13 +6,21 @@ module Windcharger
6
6
 
7
7
  private
8
8
 
9
- def attribute
10
- @__windcharger_next_is_attribute = true
9
+ def __windcharger_add_attribute name
10
+ (@__attributes ||= []) << name.to_sym
11
+ end
12
+
13
+ def attribute *attributes
14
+ if attributes.any?
15
+ attributes.each { |attribute| __windcharger_add_attribute attribute }
16
+ else
17
+ @__windcharger_next_is_attribute = true
18
+ end
11
19
  end
12
20
 
13
21
  def method_added name
14
22
  return unless @__windcharger_next_is_attribute
15
- (@__attributes ||= []) << name
23
+ __windcharger_add_attribute name
16
24
  @__windcharger_next_is_attribute = false
17
25
  end
18
26
  end
@@ -1,3 +1,3 @@
1
1
  module Windcharger
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/spec/readme_spec.rb CHANGED
@@ -42,6 +42,16 @@ describe "readme" do
42
42
  :walked_into_a_bar
43
43
  end
44
44
 
45
+ def qux
46
+ 1
47
+ end
48
+
49
+ attribute :qax, :qux
50
+
51
+ def qax
52
+ 2
53
+ end
54
+
45
55
  def not_an_attribute
46
56
  42
47
57
  end
@@ -54,7 +64,12 @@ describe "readme" do
54
64
 
55
65
  it "works" do
56
66
  my_transformer = MyTransformer.new
57
- expect(my_transformer.transform).to eq({ :foo => :the_foo, :bar => :walked_into_a_bar })
67
+ expect(my_transformer.transform).to eq({
68
+ :foo => :the_foo,
69
+ :bar => :walked_into_a_bar,
70
+ :qax => 2,
71
+ :qux => 1,
72
+ })
58
73
  end
59
74
  end
60
75
  end
@@ -12,7 +12,16 @@ describe Windcharger::Attributes do
12
12
  expect { transformer_class.attribute }.to raise_error NoMethodError, /private/
13
13
  end
14
14
 
15
- it "does not add a method not preceded by a call to attribute to the list of attributes" do
15
+ it "adds attributes to the list, not affecting the next method added, when attribute is called with params" do
16
+ transformer_class = Class.new do
17
+ extend Windcharger::Attributes
18
+ attribute :foo, :bar
19
+ def baz; end
20
+ end
21
+ expect(transformer_class.attributes).to eq [:foo, :bar]
22
+ end
23
+
24
+ it "does not add a method to attributes when its def is not preceded by a call to attribute" do
16
25
  transformer_class = Class.new do
17
26
  extend Windcharger::Attributes
18
27
 
@@ -21,7 +30,7 @@ describe Windcharger::Attributes do
21
30
  expect(transformer_class.attributes).to eq []
22
31
  end
23
32
 
24
- it "adds a method preceded by a call to attribute to the list of attributes" do
33
+ it "adds a method to attributes when its def is preceded by a call to attribute" do
25
34
  transformer_class = Class.new do
26
35
  extend Windcharger::Attributes
27
36
 
@@ -3,7 +3,7 @@ require 'windcharger/hash_transformer'
3
3
 
4
4
  describe Windcharger::HashTransformer do
5
5
  describe "#transform" do
6
- it "returns a hash with attribute names and return values from those methods" do
6
+ it "returns a hash with attribute names as keys and their method results as values" do
7
7
  transformer_class = Class.new do
8
8
  extend Windcharger::Attributes
9
9
  include Windcharger::HashTransformer
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windcharger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-20 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Small library to easily make objects that transform input via many methods.
@@ -59,8 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
64
  - Gemfile
65
65
  - LICENSE.txt
66
66
  - README.md
@@ -85,17 +85,17 @@ require_paths:
85
85
  - lib
86
86
  required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.1.9
98
+ rubygems_version: 2.2.0
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Small library to easily make objects that transform input via many methods.