shy 0.0.1 → 0.0.2
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.
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +6 -2
- data/lib/shy.rb +14 -9
- data/lib/shy/dsl.rb +10 -0
- data/shy.gemspec +1 -1
- data/spec/shy_spec.rb +41 -17
- metadata +7 -4
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
shy
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p392
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Shy
|
1
|
+
# Shy [](https://travis-ci.org/hiremaga/shy) [](https://codeclimate.com/github/hiremaga/shy)
|
2
2
|
|
3
3
|
A `Shy` is like a `Struct`, but `private` and instantiated with a `Hash`
|
4
4
|
|
@@ -20,7 +20,11 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
require 'shy'
|
22
22
|
|
23
|
-
class Shush
|
23
|
+
class Shush
|
24
|
+
include Shy
|
25
|
+
|
26
|
+
shy :foo, :bar
|
27
|
+
|
24
28
|
def to_s
|
25
29
|
"#{foo} and #{bar}"
|
26
30
|
end
|
data/lib/shy.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
module Shy
|
2
|
+
autoload :DSL, 'shy/dsl'
|
3
|
+
|
4
|
+
def self.included(klass)
|
5
|
+
klass.extend(DSL)
|
6
|
+
end
|
7
|
+
|
2
8
|
def self.new(*attribute_names)
|
9
|
+
warn 'Shy.new is deprecated, please use the Shy::DSL style instead.'
|
3
10
|
Class.new do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
11
|
+
include Shy
|
12
|
+
shy *attribute_names
|
13
|
+
end
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
16
|
+
def initialize(attributes={})
|
17
|
+
attributes.each do |name, value|
|
18
|
+
send("#{name}=", value)
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/shy/dsl.rb
ADDED
data/shy.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "shy"
|
5
|
-
spec.version = "0.0.
|
5
|
+
spec.version = "0.0.2"
|
6
6
|
spec.authors = ["Abhi Hiremagalur"]
|
7
7
|
spec.email = ["abhijit@hiremaga.com"]
|
8
8
|
spec.description = "A Shy is like a Struct, but private and instantiated with a Hash"
|
data/spec/shy_spec.rb
CHANGED
@@ -1,30 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Shy do
|
4
|
-
|
5
|
-
|
4
|
+
shared_examples_for 'a Shy class' do
|
5
|
+
it { should respond_to(:shy) }
|
6
|
+
|
7
|
+
it "can be instantiated with a hash of its attributes' values" do
|
8
|
+
shy_instance = subject.new(foo: 'Foo')
|
9
|
+
shy_instance.send(:foo).should eq('Foo')
|
10
|
+
shy_instance.send(:bar).should be_nil
|
11
|
+
|
12
|
+
expect {
|
13
|
+
shy_instance.send(:bar=, 'Bar')
|
14
|
+
}.to change { shy_instance.send(:bar) }.to('Bar')
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:private_instance_methods) { should include(:foo, :foo=, :bar, :bar=) }
|
18
|
+
|
19
|
+
it "allows its accessors to be optionally publicized" do
|
20
|
+
expect {
|
21
|
+
subject.class_eval do
|
22
|
+
public :foo
|
23
|
+
public :bar=
|
24
|
+
end
|
25
|
+
}.to change { subject.public_instance_methods(false) }.to([:foo, :bar=])
|
26
|
+
end
|
6
27
|
end
|
7
28
|
|
8
|
-
|
29
|
+
context 'when using the deprecated Struct inspired syntax' do
|
30
|
+
subject do
|
31
|
+
Shy.new(:foo, :bar)
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
Shy.should_receive(:warn)
|
36
|
+
end
|
9
37
|
|
10
|
-
|
11
|
-
shy_instance = subject.new(foo: 'Foo')
|
12
|
-
shy_instance.send(:foo).should eq('Foo')
|
13
|
-
shy_instance.send(:bar).should be_nil
|
38
|
+
it { should be_a(Class) }
|
14
39
|
|
15
|
-
|
16
|
-
shy_instance.send(:bar=, 'Bar')
|
17
|
-
}.to change { shy_instance.send(:bar) }.to('Bar')
|
40
|
+
it_behaves_like 'a Shy class'
|
18
41
|
end
|
19
42
|
|
20
|
-
|
43
|
+
context 'when using the mixin' do
|
44
|
+
subject do
|
45
|
+
Class.new do
|
46
|
+
include Shy
|
21
47
|
|
22
|
-
|
23
|
-
expect {
|
24
|
-
subject.class_eval do
|
25
|
-
public :foo
|
26
|
-
public :bar=
|
48
|
+
shy :foo, :bar
|
27
49
|
end
|
28
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
it_behaves_like 'a Shy class'
|
29
53
|
end
|
30
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -68,12 +68,15 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
70
|
- .rspec
|
71
|
+
- .ruby-gemset
|
72
|
+
- .ruby-version
|
71
73
|
- .travis.yml
|
72
74
|
- Gemfile
|
73
75
|
- LICENSE.txt
|
74
76
|
- README.md
|
75
77
|
- Rakefile
|
76
78
|
- lib/shy.rb
|
79
|
+
- lib/shy/dsl.rb
|
77
80
|
- shy.gemspec
|
78
81
|
- spec/shy_spec.rb
|
79
82
|
- spec/spec_helper.rb
|
@@ -92,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
95
|
version: '0'
|
93
96
|
segments:
|
94
97
|
- 0
|
95
|
-
hash: -
|
98
|
+
hash: -2658879884325216323
|
96
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
100
|
none: false
|
98
101
|
requirements:
|
@@ -101,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
104
|
version: '0'
|
102
105
|
segments:
|
103
106
|
- 0
|
104
|
-
hash: -
|
107
|
+
hash: -2658879884325216323
|
105
108
|
requirements: []
|
106
109
|
rubyforge_project:
|
107
110
|
rubygems_version: 1.8.25
|