morph 0.3.2 → 0.3.3
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 +2 -0
- data/Manifest +1 -1
- data/README +68 -39
- data/Rakefile +12 -7
- data/examples/forger.rb +1 -1
- data/examples/hubbit.rb +14 -13
- data/lib/morph.rb +6 -13
- data/morph.gemspec +16 -11
- data/spec/lib/morph_spec.rb +29 -11
- data/spec/morph_spec_helper.rb +12 -4
- data/spec/spec_helper.rb +3 -0
- metadata +31 -28
- data/spec/spec.opts +0 -7
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README
CHANGED
@@ -1,28 +1,21 @@
|
|
1
|
-
Morph allows you to emerge class definitions via calling assignment methods; mix with
|
1
|
+
Morph mixin allows you to emerge class definitions via calling assignment methods; mix with Nokogiri for screen scraping fun.
|
2
2
|
|
3
3
|
|
4
|
-
== Morph creating classes +
|
4
|
+
== Morph creating classes +from_csv+
|
5
5
|
|
6
|
-
Here's example code showing Morph playing with
|
6
|
+
Here's example code showing Morph playing with CSV (comma-separated values):
|
7
7
|
|
8
8
|
require 'rubygems'; require 'morph'
|
9
9
|
|
10
|
-
|
11
|
-
<councils type="array">
|
12
|
-
<council code='1'>
|
13
|
-
<name>Aberdeen City Council</name>
|
14
|
-
</council>
|
15
|
-
<council code='2'>
|
16
|
-
<name>Allerdale Borough Council</name>
|
17
|
-
</council>
|
18
|
-
</councils>]
|
10
|
+
csv = %Q[name,party\nTed Roe,red\nAli Davidson,blue\nSue Smith,green]
|
19
11
|
|
20
|
-
|
21
|
-
# => [#<Morph::
|
22
|
-
#<Morph::
|
12
|
+
people = Morph.from_csv(csv, 'person')
|
13
|
+
# => [#<Morph::Person @name="Ted Roe", @party="red">,
|
14
|
+
#<Morph::Person @name="Ali Davidson", @party="blue">,
|
15
|
+
#<Morph::Person @name="Sue Smith", @party="green">]
|
23
16
|
|
24
|
-
|
25
|
-
# => "
|
17
|
+
people.last.party
|
18
|
+
# => "green"
|
26
19
|
|
27
20
|
== Morph creating classes +from_tsv+
|
28
21
|
|
@@ -40,42 +33,75 @@ Here's example code showing Morph playing with TSV (tab-separated values):
|
|
40
33
|
people.last.party
|
41
34
|
# => "green"
|
42
35
|
|
43
|
-
== Morph
|
36
|
+
== Morph creating classes +from_xml+
|
37
|
+
|
38
|
+
Here's example code showing Morph playing with XML:
|
39
|
+
|
40
|
+
require 'rubygems'; require 'morph'
|
44
41
|
|
45
|
-
|
42
|
+
xml = %Q[<?xml version="1.0" encoding="UTF-8"?>
|
43
|
+
<councils type="array">
|
44
|
+
<council code='1'>
|
45
|
+
<name>Aberdeen City Council</name>
|
46
|
+
</council>
|
47
|
+
<council code='2'>
|
48
|
+
<name>Allerdale Borough Council</name>
|
49
|
+
</council>
|
50
|
+
</councils>]
|
46
51
|
|
47
|
-
|
52
|
+
councils = Morph.from_xml(xml)
|
53
|
+
# => [#<Morph::Council @code="1", @name="Aberdeen City Council">,
|
54
|
+
#<Morph::Council @code="2", @name="Allerdale Borough Council">]
|
55
|
+
|
56
|
+
councils.first.name
|
57
|
+
# => "Aberdeen City Council"
|
58
|
+
|
59
|
+
== Morph playing with +Nokogiri+
|
60
|
+
|
61
|
+
Here's example code showing Morph playing with Nokogiri in Ruby 1.9.2:
|
62
|
+
|
63
|
+
require 'rubygems'; require 'nokogiri'; require 'open-uri'
|
48
64
|
require 'morph'
|
49
65
|
|
50
66
|
class Hubbit
|
51
67
|
include Morph # allows class to morph
|
52
68
|
|
53
69
|
def initialize name
|
54
|
-
doc =
|
70
|
+
doc = Nokogiri::HTML open("https://github.com/#{name}")
|
55
71
|
|
56
|
-
(
|
72
|
+
profile_fields = doc.search('.vcard dt')
|
73
|
+
|
74
|
+
profile_fields.each do |node|
|
57
75
|
label = node.inner_text
|
58
|
-
value = node.
|
76
|
+
value = node.next_element.inner_text.strip
|
59
77
|
|
60
|
-
morph(label, value) # morph magic
|
78
|
+
morph(label, value) # morph magic adds accessor methods!
|
61
79
|
end
|
62
80
|
end
|
81
|
+
|
82
|
+
def member_since_date
|
83
|
+
Date.parse member_since
|
84
|
+
end
|
63
85
|
end
|
64
86
|
|
65
87
|
def Hubbit name; Hubbit.new name; end
|
66
88
|
|
67
|
-
|
68
89
|
The model emerges from the data. Let's start by looking up 'why':
|
69
90
|
|
70
91
|
why = Hubbit 'why'
|
71
92
|
|
72
93
|
What new methods do we have?
|
73
94
|
|
74
|
-
Hubbit.morph_methods
|
95
|
+
Hubbit.morph_methods.map {|m| m.to_s}
|
96
|
+
#=> ["location", "location=", "member_since", "member_since=", "name", "name="]
|
75
97
|
|
76
98
|
Ah-ha, so we have a name attribute now:
|
77
99
|
|
78
|
-
why.name # => "
|
100
|
+
why.name # => "Squatting until _why gets home."
|
101
|
+
|
102
|
+
We wrote a +member_since_date+ method in our class, let's call that now:
|
103
|
+
|
104
|
+
why.member_since_date # => Wed, 19 Aug 2009
|
79
105
|
|
80
106
|
|
81
107
|
Let's add some of why's projects:
|
@@ -85,8 +111,9 @@ Let's add some of why's projects:
|
|
85
111
|
|
86
112
|
That why's a productive fellow! Note new accessor methods have been added:
|
87
113
|
|
88
|
-
Hubbit.morph_methods
|
89
|
-
|
114
|
+
Hubbit.morph_methods.map {|m| m.to_s}
|
115
|
+
#=> ["location", "location=", "member_since", "member_since=", "name", "name=",
|
116
|
+
# "projects", "projects="]
|
90
117
|
|
91
118
|
|
92
119
|
Let's do some more morphing:
|
@@ -95,9 +122,10 @@ Let's do some more morphing:
|
|
95
122
|
|
96
123
|
Do we have more methods now?
|
97
124
|
|
98
|
-
Hubbit.morph_methods
|
99
|
-
|
100
|
-
# "
|
125
|
+
Hubbit.morph_methods.map {|m| m.to_s}
|
126
|
+
#=> ["company", "company=", "email", "email=", "location", "location=",
|
127
|
+
# "member_since", "member_since=", "name", "name=", "projects", "projects=",
|
128
|
+
# "website_blog", "website_blog="]
|
101
129
|
|
102
130
|
So, a new company method has appeared:
|
103
131
|
|
@@ -109,16 +137,17 @@ So, a new company method has appeared:
|
|
109
137
|
Time to generate an Active Record model? Get a sample script line like this:
|
110
138
|
|
111
139
|
Hubbit.script_generate
|
112
|
-
|
113
|
-
#
|
114
|
-
#
|
140
|
+
#=> "rails destroy model Hubbit;
|
141
|
+
# rails generate model Hubbit company:string email:string location:string
|
142
|
+
# member_since:string name:string projects:string website_blog:string"
|
115
143
|
|
116
144
|
or specify the generator:
|
117
145
|
|
118
|
-
Hubbit.script_generate :generator => '
|
119
|
-
|
120
|
-
#
|
121
|
-
#
|
146
|
+
Hubbit.script_generate :generator => 'rspec_model'
|
147
|
+
#=> "rails destroy rspec_model Hubbit;
|
148
|
+
# rails generate rspec_model Hubbit company:string email:string
|
149
|
+
# location:string member_since:string name:string projects:string
|
150
|
+
# website_blog:string"
|
122
151
|
|
123
152
|
You'll have to edit this as it currently sets all data types to be string, and
|
124
153
|
doesn't understand associations.
|
data/Rakefile
CHANGED
@@ -1,29 +1,34 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'lib/morph'
|
2
|
+
require './lib/morph'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require '
|
5
|
+
require 'rspec'
|
6
6
|
rescue LoadError
|
7
7
|
puts "\nYou need to install the rspec gem to perform meta operations on this gem"
|
8
|
-
puts "
|
8
|
+
puts " gem install rspec\n"
|
9
9
|
end
|
10
10
|
|
11
11
|
begin
|
12
12
|
require 'echoe'
|
13
13
|
|
14
|
-
Echoe.new("morph"
|
14
|
+
Echoe.new("morph") do |m|
|
15
15
|
m.author = ["Rob McKinnon"]
|
16
16
|
m.email = ["rob ~@nospam@~ rubyforge.org"]
|
17
|
+
m.summary = 'Morph mixin allows you to emerge class definitions via calling assignment methods.'
|
17
18
|
m.description = File.readlines("README").first
|
18
|
-
m.
|
19
|
+
m.url = 'https://github.com/robmckinnon/morph'
|
20
|
+
m.install_message = 'Read usage examples at: https://github.com/robmckinnon/morph#readme'
|
21
|
+
m.version = Morph::VERSION
|
22
|
+
m.project = "morph"
|
19
23
|
m.rdoc_options << '--inline-source'
|
20
24
|
m.rdoc_pattern = ["README", "CHANGELOG", "LICENSE"]
|
21
|
-
m.
|
25
|
+
m.runtime_dependencies = ["activesupport >=2.0.2"]
|
26
|
+
m.development_dependencies = ['rspec','echoe']
|
22
27
|
end
|
23
28
|
|
24
29
|
rescue LoadError
|
25
30
|
puts "\nYou need to install the echoe gem to perform meta operations on this gem"
|
26
|
-
puts "
|
31
|
+
puts " gem install echoe\n\n"
|
27
32
|
end
|
28
33
|
|
29
34
|
desc "Open an irb session preloaded with this library"
|
data/examples/forger.rb
CHANGED
data/examples/hubbit.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
require 'morph'
|
2
2
|
|
3
|
-
require 'rubygems'; require '
|
3
|
+
require 'rubygems'; require 'nokogiri'; require 'open-uri'
|
4
4
|
|
5
|
-
# An example of Morph playing with
|
5
|
+
# An example of Morph playing with Nokogiri
|
6
6
|
class Hubbit
|
7
|
-
|
8
|
-
include Morph
|
7
|
+
include Morph # allows class to morph
|
9
8
|
|
10
9
|
def initialize name
|
11
|
-
|
12
|
-
|
10
|
+
doc = Nokogiri::HTML open("https://github.com/#{name}")
|
11
|
+
|
12
|
+
profile_fields = doc.search('.vcard dt')
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
profile_fields.each do |node|
|
15
|
+
label = node.inner_text
|
16
|
+
value = node.next_element.inner_text.strip
|
17
17
|
|
18
|
-
|
19
|
-
end
|
20
|
-
rescue
|
21
|
-
raise "Couldn't find hubbit with name: #{name}"
|
18
|
+
morph(label, value) # morph magic adds accessor methods!
|
22
19
|
end
|
23
20
|
end
|
21
|
+
|
22
|
+
def member_since_date
|
23
|
+
Date.parse member_since
|
24
|
+
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def Hubbit name
|
data/lib/morph.rb
CHANGED
@@ -18,7 +18,7 @@ rescue Exception => e
|
|
18
18
|
end
|
19
19
|
|
20
20
|
module Morph
|
21
|
-
VERSION = "0.3.
|
21
|
+
VERSION = "0.3.3" unless defined? Morph::VERSION
|
22
22
|
|
23
23
|
class << self
|
24
24
|
def generate_migrations object, options={}
|
@@ -119,8 +119,10 @@ module Morph
|
|
119
119
|
when Hash
|
120
120
|
options[:belongs_to_id] = " #{name}_id:integer"
|
121
121
|
migrations = add_migration(attribute, value, migrations, options)
|
122
|
+
when nil
|
123
|
+
# ignore
|
122
124
|
else
|
123
|
-
puts '
|
125
|
+
puts 'not supported ' + value.inspect
|
124
126
|
end
|
125
127
|
end
|
126
128
|
migrations
|
@@ -205,20 +207,11 @@ module Morph
|
|
205
207
|
class_eval { define_method name, &block }
|
206
208
|
end
|
207
209
|
|
208
|
-
def show_ruby
|
209
|
-
begin
|
210
|
-
require 'ruby2ruby'
|
211
|
-
puts Ruby2Ruby.translate(self)
|
212
|
-
rescue LoadError
|
213
|
-
puts "You need to install the ruby2ruby gem before calling show_ruby"
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
210
|
def script_generate options={}
|
218
211
|
name = self.name.to_s.split('::').last
|
219
212
|
name = yield name if block_given?
|
220
|
-
generator = options[:generator] || '
|
221
|
-
line = ["
|
213
|
+
generator = options[:generator] || 'model'
|
214
|
+
line = ["rails destroy #{generator} #{name}; rails generate #{generator} #{name}"]
|
222
215
|
morph_methods.select{|m| not(m =~ /=$/) }.each {|attribute| line << " #{attribute}:string"}
|
223
216
|
line.join('')
|
224
217
|
end
|
data/morph.gemspec
CHANGED
@@ -1,34 +1,39 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.3.
|
4
|
+
s.name = "morph"
|
5
|
+
s.version = "0.3.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Rob McKinnon"]
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
}
|
9
|
+
s.date = "2011-09-21"
|
10
|
+
s.description = "Morph mixin allows you to emerge class definitions via calling assignment methods; mix with Nokogiri for screen scraping fun.\n"
|
12
11
|
s.email = ["rob ~@nospam@~ rubyforge.org"]
|
13
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
|
14
|
-
s.files = ["CHANGELOG", "examples/forger.rb", "examples/hubbit.rb", "lib/morph.rb", "LICENSE", "README", "spec/lib/morph_spec.rb", "spec/morph_spec_helper.rb", "spec/
|
15
|
-
s.homepage =
|
13
|
+
s.files = ["CHANGELOG", "examples/forger.rb", "examples/hubbit.rb", "lib/morph.rb", "LICENSE", "README", "spec/lib/morph_spec.rb", "spec/morph_spec_helper.rb", "spec/spec_helper.rb", "Manifest", "morph.gemspec", "Rakefile"]
|
14
|
+
s.homepage = "https://github.com/robmckinnon/morph"
|
15
|
+
s.post_install_message = "Read usage examples at: https://github.com/robmckinnon/morph#readme"
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Morph", "--main", "README", "--inline-source"]
|
17
17
|
s.require_paths = ["lib"]
|
18
|
-
s.rubyforge_project =
|
19
|
-
s.rubygems_version =
|
20
|
-
s.summary =
|
18
|
+
s.rubyforge_project = "morph"
|
19
|
+
s.rubygems_version = "1.8.10"
|
20
|
+
s.summary = "Morph mixin allows you to emerge class definitions via calling assignment methods."
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
23
|
s.specification_version = 3
|
25
24
|
|
26
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
26
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
|
27
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
28
29
|
else
|
29
30
|
s.add_dependency(%q<activesupport>, [">= 2.0.2"])
|
31
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
32
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
30
33
|
end
|
31
34
|
else
|
32
35
|
s.add_dependency(%q<activesupport>, [">= 2.0.2"])
|
36
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
37
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
33
38
|
end
|
34
39
|
end
|
data/spec/lib/morph_spec.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '/../../lib/morph'
|
3
2
|
require File.dirname(__FILE__) + '/../morph_spec_helper'
|
4
3
|
|
5
4
|
describe Morph do
|
5
|
+
include MorphSpecHelperMethods
|
6
|
+
|
6
7
|
describe "when writer method that didn't exist before is called with non-nil value" do
|
8
|
+
before :all do initialize_morph; end
|
9
|
+
after :all do remove_morph_methods; end
|
10
|
+
|
7
11
|
before :each do
|
8
12
|
remove_morph_methods
|
9
13
|
@quack = 'quack'
|
@@ -23,15 +27,15 @@ describe Morph do
|
|
23
27
|
end
|
24
28
|
|
25
29
|
it 'should generate rails model generator script line, with given model name' do
|
26
|
-
@morphed_class.script_generate {|model_name| 'SomethingDifferent'}.should == "
|
30
|
+
@morphed_class.script_generate {|model_name| 'SomethingDifferent'}.should == "rails destroy model SomethingDifferent; rails generate model SomethingDifferent noise:string"
|
27
31
|
end
|
28
32
|
|
29
33
|
it 'should generate rails model generator script line' do
|
30
|
-
@morphed_class.script_generate.should == "
|
34
|
+
@morphed_class.script_generate.should == "rails destroy model ExampleMorph; rails generate model ExampleMorph noise:string"
|
31
35
|
end
|
32
36
|
|
33
37
|
it 'should generate rails model generator script line' do
|
34
|
-
@morphed_class.script_generate(:generator=>'model').should == "
|
38
|
+
@morphed_class.script_generate(:generator=>'model').should == "rails destroy model ExampleMorph; rails generate model ExampleMorph noise:string"
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -119,7 +123,7 @@ describe Morph do
|
|
119
123
|
|
120
124
|
after :all do
|
121
125
|
remove_morph_methods
|
122
|
-
@morphed_class.class_eval "remove_method :happy"
|
126
|
+
@morphed_class.class_eval "remove_method :happy" if @morphed_class
|
123
127
|
end
|
124
128
|
|
125
129
|
it 'should not return methods defined in class in morph_methods list' do
|
@@ -139,6 +143,8 @@ describe Morph do
|
|
139
143
|
end
|
140
144
|
|
141
145
|
describe 'when morph method used to set attribute value' do
|
146
|
+
before :all do initialize_morph; end
|
147
|
+
after :all do remove_morph_methods; end
|
142
148
|
|
143
149
|
before :each do
|
144
150
|
remove_morph_methods
|
@@ -156,6 +162,9 @@ describe Morph do
|
|
156
162
|
end
|
157
163
|
|
158
164
|
describe 'when morph method used to set an attribute value hash' do
|
165
|
+
before :all do initialize_morph; end
|
166
|
+
after :all do remove_morph_methods; end
|
167
|
+
|
159
168
|
before :each do
|
160
169
|
remove_morph_methods
|
161
170
|
@attributes = [:drink,:sugars,:milk]
|
@@ -172,15 +181,19 @@ describe Morph do
|
|
172
181
|
end
|
173
182
|
|
174
183
|
it 'should generate rails model generator script line' do
|
175
|
-
@morphed_class.script_generate.should == "
|
184
|
+
@morphed_class.script_generate.should == "rails destroy model ExampleMorph; rails generate model ExampleMorph drink:string milk:string sugars:string"
|
176
185
|
end
|
177
186
|
|
178
187
|
it 'should generate rails model generator script line' do
|
179
|
-
@morphed_class.script_generate(:generator=>'model').should == "
|
188
|
+
@morphed_class.script_generate(:generator=>'model').should == "rails destroy model ExampleMorph; rails generate model ExampleMorph drink:string milk:string sugars:string"
|
180
189
|
end
|
181
190
|
end
|
182
191
|
|
192
|
+
=begin
|
183
193
|
describe "when morph method used to set unicode attribute name with a value" do
|
194
|
+
before :all do initialize_morph; end
|
195
|
+
after :all do remove_morph_methods; end
|
196
|
+
|
184
197
|
before :each do
|
185
198
|
$KCODE = "u" unless RUBY_VERSION >= "1.9"
|
186
199
|
remove_morph_methods
|
@@ -200,8 +213,10 @@ describe Morph do
|
|
200
213
|
@morph.send(@attribute.to_sym) == @age
|
201
214
|
end
|
202
215
|
end
|
203
|
-
|
204
216
|
describe "when morph method used to set japanese and latin unicode attribute name with a value" do
|
217
|
+
before :all do initialize_morph; end
|
218
|
+
after :all do remove_morph_methods; end
|
219
|
+
|
205
220
|
before :each do
|
206
221
|
$KCODE = "u" unless RUBY_VERSION >= "1.9"
|
207
222
|
remove_morph_methods
|
@@ -221,7 +236,7 @@ describe Morph do
|
|
221
236
|
@morph.send(@attribute.to_sym) == @age
|
222
237
|
end
|
223
238
|
end
|
224
|
-
|
239
|
+
=end
|
225
240
|
describe 'when morph method used to set blank space attribute value' do
|
226
241
|
before :each do
|
227
242
|
remove_morph_methods
|
@@ -265,6 +280,9 @@ describe Morph do
|
|
265
280
|
|
266
281
|
describe "when writer method called matches a class reader method" do
|
267
282
|
|
283
|
+
before :all do initialize_morph; end
|
284
|
+
after :all do remove_morph_methods; end
|
285
|
+
|
268
286
|
before :each do
|
269
287
|
remove_morph_methods
|
270
288
|
@value = 'Morph'
|
@@ -582,7 +600,7 @@ xsi_schema_location: xmlgwdev.companieshouse.gov.uk/v1-0/schema/CompanyDetails.x
|
|
582
600
|
|
583
601
|
describe 'when class name and module name is supplied' do
|
584
602
|
it 'should create classes and object instances' do
|
585
|
-
Object.const_set 'Ppc', Module.new
|
603
|
+
Object.const_set 'Ppc', Module.new unless defined? Ppc
|
586
604
|
councillors = Morph.from_tsv(tsv, 'Councillor', Ppc)
|
587
605
|
check_councillors councillors, 'Ppc::Councillor'
|
588
606
|
end
|
@@ -606,7 +624,7 @@ Ali Davidson labour Basildon District Council
|
|
606
624
|
|
607
625
|
describe 'when class name and module name is supplied' do
|
608
626
|
it 'should create classes and object instances' do
|
609
|
-
Object.const_set 'Ppc', Module.new
|
627
|
+
Object.const_set 'Ppc', Module.new unless defined? Ppc
|
610
628
|
councillors = Morph.from_csv(csv, 'Councillor', Ppc)
|
611
629
|
check_councillors councillors, 'Ppc::Councillor', nil
|
612
630
|
end
|
data/spec/morph_spec_helper.rb
CHANGED
@@ -29,8 +29,16 @@ module MorphSpecHelperMethods
|
|
29
29
|
|
30
30
|
def remove_morph_methods
|
31
31
|
@morphed_class.instance_methods.each do |method|
|
32
|
-
|
33
|
-
|
32
|
+
begin
|
33
|
+
unless method.to_s[/received_message\?|should_not_receive|rspec_verify|unstub|rspec_reset|should_receive|as_null_object|stub_chain|stub\!|null_object?|stub/]
|
34
|
+
remove_cmd = "remove_method :#{method}"
|
35
|
+
@morphed_class.class_eval remove_cmd unless @original_instance_methods.include?(method)
|
36
|
+
end
|
37
|
+
rescue Exception => e
|
38
|
+
raise e.to_s + '------' + @original_instance_methods.sort.inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
end if @morphed_class
|
34
42
|
end
|
35
43
|
|
36
44
|
def remove_another_morph_methods
|
@@ -62,7 +70,7 @@ module MorphSpecHelperMethods
|
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
65
|
-
|
73
|
+
shared_examples_for "class with generated accessor methods added" do
|
66
74
|
|
67
75
|
include MorphSpecHelperMethods
|
68
76
|
before :all do initialize_morph; end
|
@@ -106,7 +114,7 @@ describe "class with generated accessor methods added", :shared => true do
|
|
106
114
|
|
107
115
|
end
|
108
116
|
|
109
|
-
|
117
|
+
shared_examples_for "class without generated accessor methods added" do
|
110
118
|
include MorphSpecHelperMethods
|
111
119
|
|
112
120
|
before :all do
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 2
|
10
|
-
version: 0.3.2
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.3
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Rob McKinnon
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
13
|
+
date: 2011-09-21 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
16
|
name: activesupport
|
@@ -26,16 +20,33 @@ dependencies:
|
|
26
20
|
requirements:
|
27
21
|
- - ">="
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 11
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
- 2
|
34
23
|
version: 2.0.2
|
35
24
|
type: :runtime
|
36
25
|
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: echoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
37
48
|
description: |
|
38
|
-
Morph allows you to emerge class definitions via calling assignment methods; mix with
|
49
|
+
Morph mixin allows you to emerge class definitions via calling assignment methods; mix with Nokogiri for screen scraping fun.
|
39
50
|
|
40
51
|
email:
|
41
52
|
- rob ~@nospam@~ rubyforge.org
|
@@ -56,15 +67,14 @@ files:
|
|
56
67
|
- README
|
57
68
|
- spec/lib/morph_spec.rb
|
58
69
|
- spec/morph_spec_helper.rb
|
59
|
-
- spec/
|
70
|
+
- spec/spec_helper.rb
|
60
71
|
- Manifest
|
61
72
|
- morph.gemspec
|
62
73
|
- Rakefile
|
63
|
-
|
64
|
-
homepage: ""
|
74
|
+
homepage: https://github.com/robmckinnon/morph
|
65
75
|
licenses: []
|
66
76
|
|
67
|
-
post_install_message:
|
77
|
+
post_install_message: "Read usage examples at: https://github.com/robmckinnon/morph#readme"
|
68
78
|
rdoc_options:
|
69
79
|
- --line-numbers
|
70
80
|
- --inline-source
|
@@ -80,26 +90,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
90
|
requirements:
|
81
91
|
- - ">="
|
82
92
|
- !ruby/object:Gem::Version
|
83
|
-
hash: 3
|
84
|
-
segments:
|
85
|
-
- 0
|
86
93
|
version: "0"
|
87
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
95
|
none: false
|
89
96
|
requirements:
|
90
97
|
- - ">="
|
91
98
|
- !ruby/object:Gem::Version
|
92
|
-
hash: 11
|
93
|
-
segments:
|
94
|
-
- 1
|
95
|
-
- 2
|
96
99
|
version: "1.2"
|
97
100
|
requirements: []
|
98
101
|
|
99
102
|
rubyforge_project: morph
|
100
|
-
rubygems_version: 1.
|
103
|
+
rubygems_version: 1.8.10
|
101
104
|
signing_key:
|
102
105
|
specification_version: 3
|
103
|
-
summary: Morph allows you to emerge class definitions via calling assignment methods
|
106
|
+
summary: Morph mixin allows you to emerge class definitions via calling assignment methods.
|
104
107
|
test_files: []
|
105
108
|
|