eigindir 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.
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ describe Eigindir::Patches do
4
+ using described_class
5
+
6
+ describe "to Hash" do
7
+
8
+ describe "#normalize" do
9
+
10
+ let(:hash) { { "foo" => "foo", "bar" => { "baz" => "qux" } } }
11
+
12
+ it "symbolizes all keys" do
13
+ expect(hash.normalize).to eq(foo: "foo", bar: { "baz" => "qux" })
14
+ end
15
+
16
+ end # describe #normalize
17
+
18
+ describe "#slice" do
19
+
20
+ let(:hash) { { foo: "foo", bar: "bar" } }
21
+
22
+ it "returs a hash with given keys only" do
23
+ expect(hash.slice :foo).to eq(foo: "foo")
24
+ end
25
+
26
+ it "ignores unknown keys" do
27
+ expect(hash.slice :baz).to eq({})
28
+ end
29
+
30
+ end # describe #slice
31
+
32
+ end # describe Hash
33
+
34
+ end # describe Eigindir::Patches
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ describe Eigindir do
4
+
5
+ let(:coercer) { ->(value) { value.to_s } }
6
+ let(:klass) do
7
+ Class.new do
8
+ include Eigindir
9
+
10
+ private
11
+
12
+ def coercer(value)
13
+ value.to_s
14
+ end
15
+ end
16
+ end
17
+
18
+ subject(:instance) { klass.new }
19
+
20
+ describe ".included" do
21
+
22
+ it "extends class with API" do
23
+ expect(klass).to be_kind_of Eigindir::API
24
+ end
25
+
26
+ end # describe .included
27
+
28
+ describe "#attributes" do
29
+
30
+ subject do
31
+ instance.instance_eval "@foo = 1"
32
+ instance.attributes
33
+ end
34
+
35
+ it "returns coerced attributes" do
36
+ klass.attribute :foo, coerce: ->(val) { val.to_s }
37
+ expect(subject).to eq(foo: "1")
38
+ end
39
+
40
+ it "returns attributes with getter" do
41
+ klass.attribute_reader :foo, coerce: ->(val) { val.to_s }
42
+ expect(subject).to eq(foo: "1")
43
+ end
44
+
45
+ it "skips attributes without getter" do
46
+ klass.attribute_writer :foo, coerce: ->(val) { val.to_s }
47
+ expect(subject).to eq({})
48
+ end
49
+
50
+ it "skips non-attributes" do
51
+ klass.send :attr_accessor, :foo
52
+ expect(subject).to eq({})
53
+ end
54
+
55
+ end # describe #attributes
56
+
57
+ describe "#attributes=" do
58
+
59
+ subject do
60
+ instance.attributes = { "foo" => 1 }
61
+ instance.instance_eval "@foo"
62
+ end
63
+
64
+ it "sets values to coerced attributes" do
65
+ klass.attribute :foo, coerce: ->(val) { val.to_s }
66
+ expect(subject).to eq "1"
67
+ end
68
+
69
+ it "sets values to attributes with setter" do
70
+ klass.attribute_writer :foo, coerce: ->(val) { val.to_s }
71
+ expect(subject).to eq "1"
72
+ end
73
+
74
+ it "skips attributes without setter" do
75
+ klass.attribute_reader :foo, coerce: ->(val) { val.to_s }
76
+ expect(subject).to be_nil
77
+ end
78
+
79
+ it "skips non-attributes" do
80
+ klass.send :attr_accessor, :foo
81
+ expect(subject).to be_nil
82
+ end
83
+
84
+ end # describe #attributes=
85
+
86
+ end # describe Eigindir
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eigindir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kozin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hexx-rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ description:
28
+ email: andrew.kozin@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - README.md
33
+ - LICENSE
34
+ files:
35
+ - ".coveralls.yml"
36
+ - ".gitignore"
37
+ - ".metrics"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - ".travis.yml"
41
+ - ".yardopts"
42
+ - Gemfile
43
+ - Guardfile
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - config/metrics/STYLEGUIDE
48
+ - config/metrics/cane.yml
49
+ - config/metrics/churn.yml
50
+ - config/metrics/flay.yml
51
+ - config/metrics/metric_fu.yml
52
+ - config/metrics/reek.yml
53
+ - config/metrics/roodi.yml
54
+ - config/metrics/rubocop.yml
55
+ - config/metrics/saikuro.yml
56
+ - config/metrics/simplecov.yml
57
+ - config/metrics/yardstick.yml
58
+ - eigindir.gemspec
59
+ - lib/eigindir.rb
60
+ - lib/eigindir/api.rb
61
+ - lib/eigindir/coercer.rb
62
+ - lib/eigindir/patches.rb
63
+ - lib/eigindir/version.rb
64
+ - spec/spec_helper.rb
65
+ - spec/tests/eigindir/api_spec.rb
66
+ - spec/tests/eigindir/patches_spec.rb
67
+ - spec/tests/eigindir_spec.rb
68
+ homepage: https://github.com/nepalez/eigindir
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '2.1'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.6
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Declaration and coercion of PORO attributes
92
+ test_files:
93
+ - spec/spec_helper.rb
94
+ - spec/tests/eigindir_spec.rb
95
+ - spec/tests/eigindir/api_spec.rb
96
+ - spec/tests/eigindir/patches_spec.rb
97
+ has_rdoc: