morph 0.1.0 → 0.1.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/CHANGELOG +4 -0
- data/README +106 -108
- data/lib/morph.rb +14 -10
- data/morph.gemspec +12 -16
- data/spec/morph_spec.rb +74 -158
- metadata +11 -6
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,155 +1,153 @@
|
|
1
1
|
Morph allows you to emerge class definitions via calling assignment methods.
|
2
2
|
Mix with Hpricot for screen scrapping fun.
|
3
3
|
|
4
|
+
== Morph example
|
5
|
+
|
4
6
|
Here's example code showing Morph playing with Hpricot:
|
5
7
|
|
6
|
-
|
8
|
+
require 'hpricot'; require 'open-uri'; require 'morph'
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
class Hubbit
|
11
|
+
include Morph # allows class to morph
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
def initialize name
|
14
|
+
doc = Hpricot open("http://github.com/#{name}")
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
(doc/'label').collect do |node|
|
17
|
+
label = node.inner_text
|
18
|
+
value = node.next_sibling.inner_text.strip
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
morph(label, value) # morph magic happening here!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
22
24
|
|
23
|
-
|
25
|
+
def Hubbit name; Hubbit.new name; end
|
24
26
|
|
25
27
|
|
26
28
|
The model emerges from the data. Let's start by looking up 'why':
|
27
29
|
|
28
|
-
|
30
|
+
why = Hubbit 'why'
|
29
31
|
|
30
32
|
What new methods do we have?
|
31
33
|
|
32
|
-
|
34
|
+
Hubbit.morph_methods # => ["email", "email=", "name", "name="]
|
33
35
|
|
34
36
|
Ah-ha, so we have a name attribute now:
|
35
37
|
|
36
|
-
|
38
|
+
why.name #=> "why the lucky stiff"
|
37
39
|
|
38
40
|
|
39
41
|
Let's add some of why's projects:
|
40
42
|
|
41
|
-
|
42
|
-
mousehole parkplace poignant sandbox]
|
43
|
+
why.projects = %w[shoes hacketyhack camping hoodwinkd hpricot markaby mousehole parkplace poignant sandbox]
|
43
44
|
|
44
45
|
That why's a productive fellow! Note new accessor methods have been added:
|
45
46
|
|
46
|
-
|
47
|
-
"projects", "projects="]
|
47
|
+
Hubbit.morph_methods # => ["email", "email=", "name", "name=", "projects", "projects="]
|
48
48
|
|
49
49
|
|
50
50
|
Let's do some more morphing:
|
51
51
|
|
52
|
-
|
52
|
+
dhh = Hubbit 'dhh'
|
53
53
|
|
54
54
|
Do we have more methods now?
|
55
55
|
|
56
|
-
|
57
|
-
"email", "email=", "location", "location="
|
58
|
-
"name", "name=", "projects", "projects="]
|
56
|
+
Hubbit.morph_methods # => ["blog", "blog=", "company", "company=", "email", "email=", "location", "location=" "name", "name=", "projects", "projects="]
|
59
57
|
|
60
58
|
So, a new company method has appeared:
|
61
59
|
|
62
|
-
|
60
|
+
dhh.company #=> "37signals"
|
63
61
|
|
64
62
|
|
65
63
|
Time to print the nascent attribute definitions:
|
66
64
|
|
67
|
-
|
65
|
+
puts Hubbit.print_morph_methods
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
# attr_accessor :name
|
68
|
+
# attr_accessor :email
|
69
|
+
# attr_accessor :blog
|
70
|
+
# attr_accessor :company
|
71
|
+
# attr_accessor :location
|
72
|
+
# attr_accessor :projects
|
75
73
|
|
76
74
|
|
77
75
|
See examples/ directory for more example code.
|
78
76
|
See LICENSE for the terms of this software.
|
79
77
|
|
80
|
-
,
|
81
|
-
?7+~::+II~
|
82
|
-
?7: ,:+7
|
83
|
-
777IIII777? 7: :?7
|
84
|
-
=I= I: 7? ,+7
|
85
|
-
I? ,, 77 7: :I
|
86
|
-
= ?7777 77 7 7 7+, :7
|
87
|
-
7 777777 ~77+=77 I+ I? ,7
|
88
|
-
:7 77 ~77 I I7 7 ?: ?
|
89
|
-
I 77 7, 7 7 :I I ?
|
90
|
-
7 ?77=7~ 77777 7 ~+ ,+
|
91
|
-
7~ 7 :I7?~ 7
|
92
|
-
=? 7 ?I ~I77= I=
|
93
|
-
7 ? :, 7 I7777, 7 7
|
94
|
-
? 777?~~7777+ 7 7~ 7
|
95
|
-
?7 ,777777=, ,7 7 ,7
|
96
|
-
7= , =7 7: 7
|
97
|
-
+7 :7 7 ,I
|
98
|
-
:7 ?~ 7? 7
|
99
|
-
7 7 ~II7~, 7
|
100
|
-
7 7 , =7777777?+,,, I=
|
101
|
-
:7, ~==, 7
|
102
|
-
II~,, 77~
|
103
|
-
,I? +777
|
104
|
-
7+, ~7777:
|
105
|
-
== :77
|
106
|
-
:7: ,7I
|
107
|
-
7I 7
|
108
|
-
I ,7, 7
|
109
|
-
=7 77=7 7
|
110
|
-
,7 7I 7 7
|
111
|
-
I, I7 7 7
|
112
|
-
?, ,7 7, 7
|
113
|
-
7 7~ 7, 7
|
114
|
-
7 ,7I 7 7
|
115
|
-
=+ =7 7 ~=
|
116
|
-
=7 7, 7 7
|
117
|
-
,7, ~7IIII7+, 7
|
118
|
-
+: II I
|
119
|
-
?7 I? +~
|
120
|
-
II, +I 7
|
121
|
-
~7 ,I 7
|
122
|
-
7= ~7 7
|
123
|
-
?7, ~7+ ?~
|
124
|
-
~7777I= ,7
|
125
|
-
7: 7
|
126
|
-
I 7
|
127
|
-
I ,:77I 7
|
128
|
-
I :7 I
|
129
|
-
I =~
|
130
|
-
7 , ,7
|
131
|
-
+, 7 : ,7
|
132
|
-
+ 7 + 7
|
133
|
-
+ 7 + ,7
|
134
|
-
7 I ? ,7
|
135
|
-
7 +: 7 ,7
|
136
|
-
7 =+ 7 ,7
|
137
|
-
7 :I I ,7
|
138
|
-
7 :I 7 7
|
139
|
-
7 :I I 7
|
140
|
-
I, ,7 I: 7
|
141
|
-
=+ ,7 ? 7
|
142
|
-
:?, ,7 7, 7
|
143
|
-
I: ,7 7, ?
|
144
|
-
:7 ,7 7, ,
|
145
|
-
+I, : ? ,=
|
146
|
-
+= ~ =~ 7
|
147
|
-
:II,, = I ?
|
148
|
-
=I= ? 7, :7
|
149
|
-
II~ I 7, ,II
|
150
|
-
7~ ~7 7 ,=7
|
151
|
-
= =7 I, ::
|
152
|
-
77II?==?II777777777777777 7~ 7
|
153
|
-
77+,, 7:
|
154
|
-
777777+:,~777
|
155
|
-
|
78
|
+
. ,
|
79
|
+
. ?7+~::+II~
|
80
|
+
. ?7: ,:+7
|
81
|
+
. 777IIII777? 7: :?7
|
82
|
+
. =I= I: 7? ,+7
|
83
|
+
. I? ,, 77 7: :I
|
84
|
+
. = ?7777 77 7 7 7+, :7
|
85
|
+
. 7 777777 ~77+=77 I+ I? ,7
|
86
|
+
. :7 77 ~77 I I7 7 ?: ?
|
87
|
+
. I 77 7, 7 7 :I I ?
|
88
|
+
. 7 ?77=7~ 77777 7 ~+ ,+
|
89
|
+
. 7~ 7 :I7?~ 7
|
90
|
+
. =? 7 ?I ~I77= I=
|
91
|
+
. 7 ? :, 7 I7777, 7 7
|
92
|
+
. ? 777?~~7777+ 7 7~ 7
|
93
|
+
. ?7 ,777777=, ,7 7 ,7
|
94
|
+
. 7= , =7 7: 7
|
95
|
+
. +7 :7 7 ,I
|
96
|
+
. :7 ?~ 7? 7
|
97
|
+
. 7 7 ~II7~, 7
|
98
|
+
. 7 7 , =7777777?+,,, I=
|
99
|
+
. :7, ~==, 7
|
100
|
+
. II~,, 77~
|
101
|
+
. ,I? +777
|
102
|
+
. 7+, ~7777:
|
103
|
+
. == :77
|
104
|
+
. :7: ,7I
|
105
|
+
. 7I 7
|
106
|
+
. I ,7, 7
|
107
|
+
. =7 77=7 7
|
108
|
+
. ,7 7I 7 7
|
109
|
+
. I, I7 7 7
|
110
|
+
. ?, ,7 7, 7
|
111
|
+
. 7 7~ 7, 7
|
112
|
+
. 7 ,7I 7 7
|
113
|
+
. =+ =7 7 ~=
|
114
|
+
. =7 7, 7 7
|
115
|
+
. ,7, ~7IIII7+, 7
|
116
|
+
. +: II I
|
117
|
+
. ?7 I? +~
|
118
|
+
. II, +I 7
|
119
|
+
. ~7 ,I 7
|
120
|
+
. 7= ~7 7
|
121
|
+
. ?7, ~7+ ?~
|
122
|
+
. ~7777I= ,7
|
123
|
+
. 7: 7
|
124
|
+
. I 7
|
125
|
+
. I ,:77I 7
|
126
|
+
. I :7 I
|
127
|
+
. I =~
|
128
|
+
. 7 , ,7
|
129
|
+
. +, 7 : ,7
|
130
|
+
. + 7 + 7
|
131
|
+
. + 7 + ,7
|
132
|
+
. 7 I ? ,7
|
133
|
+
. 7 +: 7 ,7
|
134
|
+
. 7 =+ 7 ,7
|
135
|
+
. 7 :I I ,7
|
136
|
+
. 7 :I 7 7
|
137
|
+
. 7 :I I 7
|
138
|
+
. I, ,7 I: 7
|
139
|
+
. =+ ,7 ? 7
|
140
|
+
. :?, ,7 7, 7
|
141
|
+
. I: ,7 7, ?
|
142
|
+
. :7 ,7 7, ,
|
143
|
+
. +I, : ? ,=
|
144
|
+
. += ~ =~ 7
|
145
|
+
. :II,, = I ?
|
146
|
+
. =I= ? 7, :7
|
147
|
+
. II~ I 7, ,II
|
148
|
+
. 7~ ~7 7 ,=7
|
149
|
+
. = =7 I, ::
|
150
|
+
. 77II?==?II777777777777777 7~ 7
|
151
|
+
. 77+,, 7:
|
152
|
+
. 777777+:,~777
|
153
|
+
.
|
data/lib/morph.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Morph
|
2
|
-
VERSION = "0.1.
|
2
|
+
VERSION = "0.1.2"
|
3
3
|
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
@@ -64,18 +64,22 @@ module Morph
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def method_missing symbol, *args
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
is_writer = symbol.to_s =~ /=\Z/
|
68
|
+
|
69
|
+
if is_writer
|
70
|
+
attribute = symbol.to_s.chomp '='
|
71
|
+
if Object.instance_methods.include?(attribute)
|
72
|
+
raise "'#{attribute}' is an instance_method on Object, cannot create accessor methods for '#{attribute}'"
|
73
|
+
elsif args.size > 0
|
73
74
|
value = args[0]
|
74
75
|
empty_value = (value.nil? or (value.is_a?(String) && value.strip.size == 0))
|
75
|
-
|
76
|
+
unless empty_value
|
77
|
+
self.class.morph_accessor attribute.to_sym
|
78
|
+
send(symbol, *args)
|
79
|
+
end
|
76
80
|
end
|
77
|
-
|
78
|
-
|
81
|
+
else
|
82
|
+
super
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|
data/morph.gemspec
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Morph-0.1.
|
2
|
+
# Gem::Specification for Morph-0.1.2
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{morph}
|
7
|
-
s.version = "0.1.
|
7
|
+
s.version = "0.1.2"
|
8
8
|
|
9
9
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
11
|
s.authors = ["Rob McKinnon"]
|
13
|
-
s.date = %q{2008-03-
|
12
|
+
s.date = %q{2008-03-25}
|
14
13
|
s.description = %q{Morph allows you to emerge class definitions via calling assignment methods.}
|
15
14
|
s.email = ["rob ~@nospam@~ rubyforge.org"]
|
16
15
|
s.files = ["CHANGELOG", "examples/forger.rb", "examples/hubbit.rb", "lib/morph.rb", "LICENSE", "README", "spec/morph_spec.rb", "spec/spec.opts", "Manifest", "morph.gemspec"]
|
17
16
|
s.has_rdoc = true
|
17
|
+
s.rdoc_options += ['--quiet', '--inline-source', '--main', 'README']
|
18
|
+
s.extra_rdoc_files = ["README", "CHANGELOG", "LICENSE"]
|
18
19
|
s.homepage = %q{}
|
19
20
|
s.require_paths = ["lib"]
|
20
21
|
s.rubyforge_project = %q{morph}
|
@@ -32,11 +33,13 @@ end
|
|
32
33
|
# begin
|
33
34
|
# require 'echoe'
|
34
35
|
#
|
35
|
-
# Echoe.new("morph", Morph::VERSION) do |
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
36
|
+
# Echoe.new("morph", Morph::VERSION) do |m|
|
37
|
+
# m.author = ["Rob McKinnon"]
|
38
|
+
# m.email = ["rob ~@nospam@~ rubyforge.org"]
|
39
|
+
# m.description = File.readlines("README").first
|
40
|
+
# m.rubyforge_name = "morph"
|
41
|
+
# m.rdoc_options << '--inline-source'
|
42
|
+
# m.rdoc_pattern = ["README", "CHANGELOG", "LICENSE", "lib/*"]
|
40
43
|
# end
|
41
44
|
#
|
42
45
|
# rescue LoadError
|
@@ -47,10 +50,3 @@ end
|
|
47
50
|
# task :console do
|
48
51
|
# sh "irb -rubygems -r ./lib/morph.rb"
|
49
52
|
# end
|
50
|
-
#
|
51
|
-
# desc "Run spec runner"
|
52
|
-
# task(:test) do
|
53
|
-
# files = FileList['spec/**/*_spec.rb']
|
54
|
-
# Spec::Runner::CommandLine.run(rspec_options)
|
55
|
-
# system "ruby spec/spec_runner.rb #{files} --format specdoc"
|
56
|
-
# end
|
data/spec/morph_spec.rb
CHANGED
@@ -1,135 +1,64 @@
|
|
1
|
-
$KCODE = "u"
|
2
|
-
|
3
1
|
require File.dirname(__FILE__) + '/../lib/morph'
|
2
|
+
require File.dirname(__FILE__) + '/morph_spec_helper'
|
4
3
|
|
5
|
-
module MorphSpecHelperMethods
|
6
|
-
|
7
|
-
def initialize_morph_class
|
8
|
-
@morphed_class = eval 'class ExampleMorph; include Morph; end'
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize_morph
|
12
|
-
initialize_morph_class
|
13
|
-
@original_instance_methods = @morphed_class.instance_methods
|
14
|
-
@morph = @morphed_class.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def remove_morph_methods
|
18
|
-
@morphed_class.instance_methods.each do |method|
|
19
|
-
@morphed_class.class_eval "remove_method :#{method}" unless @original_instance_methods.include?(method)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def instance_methods
|
24
|
-
@morphed_class.instance_methods
|
25
|
-
end
|
26
|
-
|
27
|
-
def morph_methods
|
28
|
-
@morphed_class.morph_methods
|
29
|
-
end
|
30
|
-
|
31
|
-
def check_convert_to_morph_method_name label, method_name
|
32
|
-
initialize_morph_class
|
33
|
-
@morphed_class.convert_to_morph_method_name(label).should == method_name
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "class with generated accessor methods added", :shared => true do
|
38
|
-
|
39
|
-
include MorphSpecHelperMethods
|
40
|
-
before :all do initialize_morph; end
|
41
|
-
after :all do remove_morph_methods; end
|
42
|
-
|
43
|
-
it 'should add reader method to class instance_methods list' do
|
44
|
-
instance_methods.include?(@attribute).should == true
|
45
|
-
end
|
46
4
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
it 'should add writer method to class morph_methods list' do
|
56
|
-
morph_methods.include?("#{@attribute}=").should == true
|
5
|
+
describe Morph, "when writer method that didn't exist before is called with non-nil value" do
|
6
|
+
before :each do
|
7
|
+
remove_morph_methods
|
8
|
+
@quack = 'quack'
|
9
|
+
@morph.noise= @quack
|
10
|
+
@attribute = 'noise'
|
11
|
+
@expected_morph_methods_count = 2
|
57
12
|
end
|
58
13
|
|
59
|
-
|
60
|
-
morph_methods.size.should == @expected_morph_methods_count
|
61
|
-
end
|
14
|
+
it_should_behave_like "class with generated accessor methods added"
|
62
15
|
|
63
|
-
it 'should
|
64
|
-
@
|
16
|
+
it 'should return assigned value when reader method called' do
|
17
|
+
@morph.noise.should == @quack
|
65
18
|
end
|
66
19
|
end
|
67
20
|
|
68
|
-
describe "
|
69
|
-
|
70
|
-
|
71
|
-
before :all do
|
72
|
-
initialize_morph
|
73
|
-
end
|
74
|
-
|
75
|
-
after :all do
|
21
|
+
describe Morph, "when writer method that didn't exist before is called with nil value" do
|
22
|
+
before :each do
|
76
23
|
remove_morph_methods
|
24
|
+
@morph.noise= nil
|
25
|
+
@attribute = 'noise'
|
77
26
|
end
|
78
27
|
|
79
|
-
|
80
|
-
instance_methods.include?(@attribute).should == false
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should not add writer method to class instance_methods list' do
|
84
|
-
instance_methods.include?("#{@attribute}=").should == false
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should not add reader method to class morph_methods list' do
|
88
|
-
morph_methods.include?(@attribute).should == false
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should not add writer method to class morph_methods list' do
|
92
|
-
morph_methods.include?("#{@attribute}=").should == false
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should have empty morph_methods list' do
|
96
|
-
morph_methods.size.should == 0
|
97
|
-
end
|
28
|
+
it_should_behave_like "class without generated accessor methods added"
|
98
29
|
end
|
99
30
|
|
100
|
-
describe Morph, "when
|
31
|
+
describe Morph, "when writer method that didn't exist before is called with blank space attribute value" do
|
101
32
|
before :each do
|
102
33
|
remove_morph_methods
|
103
|
-
@morph.noise
|
34
|
+
@morph.noise= ' '
|
104
35
|
@attribute = 'noise'
|
105
|
-
@expected_morph_methods_count = 2
|
106
36
|
end
|
107
37
|
|
108
|
-
it_should_behave_like "class
|
109
|
-
|
110
|
-
it 'should return nil if reader is called' do
|
111
|
-
@morph.noise.should == nil
|
112
|
-
end
|
38
|
+
it_should_behave_like "class without generated accessor methods added"
|
113
39
|
end
|
114
40
|
|
115
|
-
|
41
|
+
|
42
|
+
describe Morph, 'when morph method used to set attribute value' do
|
43
|
+
|
116
44
|
before :each do
|
117
45
|
remove_morph_methods
|
118
|
-
@
|
119
|
-
@morph.
|
120
|
-
@attribute = '
|
46
|
+
@value = '20 Mar 2008'
|
47
|
+
@morph.morph('Reading', @value)
|
48
|
+
@attribute = 'reading'
|
121
49
|
@expected_morph_methods_count = 2
|
122
50
|
end
|
123
51
|
|
124
52
|
it_should_behave_like "class with generated accessor methods added"
|
125
53
|
|
126
54
|
it 'should return assigned value when reader method called' do
|
127
|
-
@morph.
|
55
|
+
@morph.reading.should == @value
|
128
56
|
end
|
129
57
|
end
|
130
58
|
|
131
|
-
describe Morph, "when
|
59
|
+
describe Morph, "when morph method used to set unicode attribute name with a value" do
|
132
60
|
before :each do
|
61
|
+
$KCODE = "u"
|
133
62
|
remove_morph_methods
|
134
63
|
@age = 19
|
135
64
|
@attribute = "年龄"
|
@@ -137,6 +66,10 @@ describe Morph, "when writer method that didn't exist before is in unicode" do
|
|
137
66
|
@expected_morph_methods_count = 2
|
138
67
|
end
|
139
68
|
|
69
|
+
after :all do
|
70
|
+
$KCODE = "NONE"
|
71
|
+
end
|
72
|
+
|
140
73
|
it_should_behave_like "class with generated accessor methods added"
|
141
74
|
|
142
75
|
it 'should return assigned value when reader method called' do
|
@@ -144,16 +77,6 @@ describe Morph, "when writer method that didn't exist before is in unicode" do
|
|
144
77
|
end
|
145
78
|
end
|
146
79
|
|
147
|
-
describe Morph, "when writer method that didn't exist before is called with nil value" do
|
148
|
-
before :each do
|
149
|
-
remove_morph_methods
|
150
|
-
@morph.morph('Pizza', nil)
|
151
|
-
@attribute = 'pizza'
|
152
|
-
end
|
153
|
-
|
154
|
-
it_should_behave_like "class without generated accessor methods added"
|
155
|
-
end
|
156
|
-
|
157
80
|
describe Morph, 'when morph method used to set blank space attribute value' do
|
158
81
|
before :each do
|
159
82
|
remove_morph_methods
|
@@ -175,47 +98,27 @@ describe Morph, 'when morph method used to set nil attribute value' do
|
|
175
98
|
end
|
176
99
|
|
177
100
|
|
178
|
-
describe Morph,
|
101
|
+
describe Morph, "when reader method that didn't exist before is called" do
|
179
102
|
|
180
103
|
include MorphSpecHelperMethods
|
181
|
-
before :all do initialize_morph; end
|
182
|
-
after :all do remove_morph_methods; end
|
183
|
-
|
184
|
-
before :each do
|
185
|
-
remove_morph_methods
|
186
|
-
@morph.noise= 'quack'
|
187
|
-
@attribute = 'noise'
|
188
|
-
@morphed_class.remove_morph_writers
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'should remove a morph generated writer method from morph_methods list' do
|
192
|
-
morph_methods.include?('noise=').should == false
|
193
|
-
morph_methods.size.should == 1
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'should remove a morph generated writer method from class instance_methods list' do
|
197
|
-
instance_methods.include?('noise=').should == false
|
198
|
-
end
|
199
104
|
|
200
|
-
it 'should
|
201
|
-
|
105
|
+
it 'should raise NoMethodError' do
|
106
|
+
initialize_morph
|
107
|
+
lambda { @morph.noise }.should raise_error(/undefined method `noise'/)
|
202
108
|
end
|
203
|
-
|
204
109
|
end
|
205
110
|
|
206
|
-
describe Morph, "when reader method called is a class method" do
|
111
|
+
describe Morph, "when reader method called that didn't exist before is a class method" do
|
207
112
|
|
208
|
-
|
209
|
-
remove_morph_methods
|
210
|
-
@morph.name
|
211
|
-
@attribute = 'name'
|
212
|
-
@expected_morph_methods_count = 2
|
213
|
-
end
|
113
|
+
include MorphSpecHelperMethods
|
214
114
|
|
215
|
-
|
115
|
+
it 'should raise NoMethodError' do
|
116
|
+
initialize_morph
|
117
|
+
lambda { @morph.name }.should raise_error(/undefined method `name'/)
|
118
|
+
end
|
216
119
|
end
|
217
120
|
|
218
|
-
describe Morph, "when writer method called
|
121
|
+
describe Morph, "when writer method called matches a class reader method" do
|
219
122
|
|
220
123
|
before :each do
|
221
124
|
remove_morph_methods
|
@@ -232,6 +135,7 @@ describe Morph, "when writer method called is a class method" do
|
|
232
135
|
end
|
233
136
|
end
|
234
137
|
|
138
|
+
|
235
139
|
describe Morph, "when class= is called" do
|
236
140
|
|
237
141
|
include MorphSpecHelperMethods
|
@@ -247,6 +151,36 @@ describe Morph, "when class= is called" do
|
|
247
151
|
end
|
248
152
|
end
|
249
153
|
|
154
|
+
|
155
|
+
describe Morph, 'when remove_morph_writers is called after a generated method has been added' do
|
156
|
+
|
157
|
+
include MorphSpecHelperMethods
|
158
|
+
before :all do initialize_morph; end
|
159
|
+
after :all do remove_morph_methods; end
|
160
|
+
|
161
|
+
before :each do
|
162
|
+
remove_morph_methods
|
163
|
+
@morph.noise= 'quack'
|
164
|
+
@attribute = 'noise'
|
165
|
+
@morphed_class.remove_morph_writers
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should remove a morph generated writer method from morph_methods list' do
|
169
|
+
morph_methods.include?('noise=').should == false
|
170
|
+
morph_methods.size.should == 1
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should remove a morph generated writer method from class instance_methods list' do
|
174
|
+
instance_methods.include?('noise=').should == false
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should be able to print morph method declarations' do
|
178
|
+
@morphed_class.print_morph_methods.should == %Q|attr_reader :#{@attribute}|
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
|
250
184
|
describe Morph, "when converting label text to morph method name" do
|
251
185
|
|
252
186
|
include MorphSpecHelperMethods
|
@@ -288,21 +222,3 @@ describe Morph, "when converting label text to morph method name" do
|
|
288
222
|
check_convert_to_morph_method_name '年龄', '年龄'
|
289
223
|
end
|
290
224
|
end
|
291
|
-
|
292
|
-
describe Morph, 'when morph method used to set attribute value and attribute name ends with colon' do
|
293
|
-
|
294
|
-
before :each do
|
295
|
-
remove_morph_methods
|
296
|
-
@value = '20 Mar 2008'
|
297
|
-
@morph.morph('First reading : ', @value)
|
298
|
-
@attribute = 'first_reading'
|
299
|
-
@expected_morph_methods_count = 2
|
300
|
-
end
|
301
|
-
|
302
|
-
it_should_behave_like "class with generated accessor methods added"
|
303
|
-
|
304
|
-
it 'should return assigned value when reader method called' do
|
305
|
-
@morph.first_reading.should == @value
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob McKinnon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-25 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,8 +20,10 @@ executables: []
|
|
20
20
|
|
21
21
|
extensions: []
|
22
22
|
|
23
|
-
extra_rdoc_files:
|
24
|
-
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
- CHANGELOG
|
26
|
+
- LICENSE
|
25
27
|
files:
|
26
28
|
- CHANGELOG
|
27
29
|
- examples/forger.rb
|
@@ -36,8 +38,11 @@ files:
|
|
36
38
|
has_rdoc: true
|
37
39
|
homepage: ""
|
38
40
|
post_install_message:
|
39
|
-
rdoc_options:
|
40
|
-
|
41
|
+
rdoc_options:
|
42
|
+
- --quiet
|
43
|
+
- --inline-source
|
44
|
+
- --main
|
45
|
+
- README
|
41
46
|
require_paths:
|
42
47
|
- lib
|
43
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|