morph 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +2 -0
  3. data/README +2 -2
  4. data/lib/morph.rb +35 -40
  5. data/morph.gemspec +4 -4
  6. metadata +16 -26
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c12c6f354c52dd3e39c28ea48a9a6aaac2dea6b3
4
+ data.tar.gz: a56834d98a549d7a5e7b8a218bda2d0adb7a3acc
5
+ SHA512:
6
+ metadata.gz: 521c12953766c73f27ef1409264b448d5fe76df0b236ecd9a6e6a1dc6cd2cf3bf6094e3f179f19d63f5ffbae1b17db785b5f372f19eab764fbe62f109382f5f6
7
+ data.tar.gz: e049d3f4e85e0510602886c090cc37ede43b8fdd1f1d18756f7cc110488c68afa1f7d2e3955b7934e88307377cedf18ee1d62ac6a85cfbc71279432701f28c6a
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.3.7. don't mix in private methods when Morph is included
2
+
1
3
  v0.3.6. call to_time() on XMLRPC::DateTime when setting it as an attribute value
2
4
 
3
5
  v0.3.5. retain morph_methods when inheriting class and parent both include Morph
data/README CHANGED
@@ -147,7 +147,7 @@ So, a new company method has appeared:
147
147
 
148
148
  Time to generate an Active Record model? Get a sample script line like this:
149
149
 
150
- Hubbit.script_generate
150
+ Morph.script_generate(Hubbit)
151
151
 
152
152
  #=> "rails destroy model Hubbit;
153
153
  # rails generate model Hubbit company:string email:string location:string
@@ -155,7 +155,7 @@ Time to generate an Active Record model? Get a sample script line like this:
155
155
 
156
156
  or specify the generator:
157
157
 
158
- Hubbit.script_generate :generator => 'rspec_model'
158
+ Morph.script_generate(Hubbit, :generator => 'rspec_model')
159
159
 
160
160
  #=> "rails destroy rspec_model Hubbit;
161
161
  # rails generate rspec_model Hubbit company:string email:string
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.6" unless defined? Morph::VERSION
21
+ VERSION = "0.3.7" unless defined? Morph::VERSION
22
22
 
23
23
  class << self
24
24
  def generate_migrations object, options={}
@@ -93,6 +93,15 @@ module Morph
93
93
  end
94
94
  end
95
95
 
96
+ def script_generate morphed_class, options={}
97
+ name = morphed_class.name.to_s.split('::').last
98
+ name = yield name if block_given?
99
+ generator = options[:generator] || 'model'
100
+ line = ["rails destroy #{generator} #{name}; rails generate #{generator} #{name}"]
101
+ morphed_class.morph_methods.select{|m| not(m =~ /=$/) }.each {|attribute| line << " #{attribute}:string"}
102
+ line.join('')
103
+ end
104
+
96
105
  def included(base)
97
106
  base.extend ClassMethods
98
107
  base.send(:include, InstanceMethods)
@@ -211,21 +220,10 @@ module Morph
211
220
  methods
212
221
  end
213
222
 
214
- def adding_morph_method= true_or_false
215
- @@adding_morph_method[self] = true_or_false
216
- end
217
-
218
- def class_def name, &block
219
- class_eval { define_method name, &block }
220
- end
221
-
222
- def script_generate options={}
223
- name = self.name.to_s.split('::').last
224
- name = yield name if block_given?
225
- generator = options[:generator] || 'model'
226
- line = ["rails destroy #{generator} #{name}; rails generate #{generator} #{name}"]
227
- morph_methods.select{|m| not(m =~ /=$/) }.each {|attribute| line << " #{attribute}:string"}
228
- line.join('')
223
+ def add_morph_attribute attribute, *args
224
+ @@adding_morph_method[self] = true
225
+ class_eval "attr_accessor :#{attribute}"
226
+ @@adding_morph_method[self] = false
229
227
  end
230
228
 
231
229
  protected
@@ -251,7 +249,11 @@ module Morph
251
249
  module MethodMissing
252
250
  def method_missing symbol, *args
253
251
  is_writer = symbol.to_s =~ /=$/
254
- is_writer ? morph_method_missing(symbol, *args) : super
252
+ if is_writer
253
+ Morph::InstanceMethods::Helper.morph_method_missing(self, symbol, *args)
254
+ else
255
+ super
256
+ end
255
257
  end
256
258
  end
257
259
 
@@ -280,7 +282,7 @@ module Morph
280
282
  if attributes_or_label.is_a? Hash
281
283
  attributes_or_label.each { |a, v| morph(a, v) }
282
284
  else
283
- attribute = convert_to_morph_method_name(attributes_or_label)
285
+ attribute = Helper.convert_to_morph_method_name(attributes_or_label)
284
286
  send("#{attribute}=".to_sym, value)
285
287
  end
286
288
  end
@@ -305,39 +307,32 @@ module Morph
305
307
  end
306
308
  end
307
309
 
308
- def morph_method_missing symbol, *args
309
- attribute = symbol.to_s.chomp '='
310
- if RUBY_VERSION >= "1.9"
311
- attribute = attribute.to_sym
312
- end
310
+ module Helper
313
311
 
314
- if Object.instance_methods.include?(attribute)
315
- raise "'#{attribute}' is an instance_method on Object, cannot create accessor methods for '#{attribute}'"
316
- elsif argument_provided? args
317
- base = self.class
318
- base.adding_morph_method = true
312
+ def self.morph_method_missing object, symbol, *args
313
+ attribute = symbol.to_s.chomp '='
314
+ if RUBY_VERSION >= "1.9"
315
+ attribute = attribute.to_sym
316
+ end
319
317
 
320
- if block_given?
321
- yield base, attribute
322
- else
323
- # base.class_eval "attr_accessor :#{attribute}"
324
- base.class_eval "def #{attribute}; @#{attribute}; end; def #{attribute}=(value); @#{attribute} = value; end"
325
- send(symbol, *args)
318
+ if Object.instance_methods.include?(attribute)
319
+ raise "'#{attribute}' is an instance_method on Object, cannot create accessor methods for '#{attribute}'"
320
+ elsif Helper.argument_provided? args
321
+ base = object.class
322
+ base.add_morph_attribute attribute
323
+ object.send(symbol, *args)
326
324
  end
327
- base.adding_morph_method = false
328
325
  end
329
- end
330
326
 
331
- private
332
-
333
- def argument_provided? args
327
+ def self.argument_provided? args
334
328
  args.size > 0 && !args[0].nil? && !(args[0].is_a?(String) && args[0].strip.size == 0)
335
329
  end
336
330
 
337
- def convert_to_morph_method_name label
331
+ def self.convert_to_morph_method_name label
338
332
  name = label.to_s.downcase.tr('()\-*',' ').gsub("'",' ').gsub('/',' ').gsub('%','percentage').strip.chomp(':').strip.gsub(/\s/,'_').squeeze('_')
339
333
  name = '_'+name if name =~ /^\d/
340
334
  name
341
335
  end
336
+ end
342
337
  end
343
338
  end
data/morph.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "morph"
5
- s.version = "0.3.6"
5
+ s.version = "0.3.7"
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 = "2013-06-03"
9
+ s.date = "2014-02-24"
10
10
  s.description = "Morph mixin allows you to emerge Ruby class definitions from data via calling assignment methods.\n"
11
11
  s.email = ["rob ~@nospam@~ rubyforge.org"]
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Morph", "--main", "README", "--inline-source"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = "morph"
19
- s.rubygems_version = "1.8.23"
19
+ s.rubygems_version = "2.0.3"
20
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
- s.specification_version = 3
23
+ s.specification_version = 4
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
26
  s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
metadata CHANGED
@@ -1,68 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
5
- prerelease:
4
+ version: 0.3.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rob McKinnon
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.0.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.0.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: echoe
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
- description: ! 'Morph mixin allows you to emerge Ruby class definitions from data
63
- via calling assignment methods.
64
-
65
- '
55
+ description: |
56
+ Morph mixin allows you to emerge Ruby class definitions from data via calling assignment methods.
66
57
  email:
67
58
  - rob ~@nospam@~ rubyforge.org
68
59
  executables: []
@@ -81,7 +72,8 @@ files:
81
72
  - Rakefile
82
73
  homepage: https://github.com/robmckinnon/morph
83
74
  licenses: []
84
- post_install_message: ! 'Read usage examples at: https://github.com/robmckinnon/morph#readme'
75
+ metadata: {}
76
+ post_install_message: 'Read usage examples at: https://github.com/robmckinnon/morph#readme'
85
77
  rdoc_options:
86
78
  - --line-numbers
87
79
  - --inline-source
@@ -93,22 +85,20 @@ rdoc_options:
93
85
  require_paths:
94
86
  - lib
95
87
  required_ruby_version: !ruby/object:Gem::Requirement
96
- none: false
97
88
  requirements:
98
- - - ! '>='
89
+ - - '>='
99
90
  - !ruby/object:Gem::Version
100
91
  version: '0'
101
92
  required_rubygems_version: !ruby/object:Gem::Requirement
102
- none: false
103
93
  requirements:
104
- - - ! '>='
94
+ - - '>='
105
95
  - !ruby/object:Gem::Version
106
96
  version: '1.2'
107
97
  requirements: []
108
98
  rubyforge_project: morph
109
- rubygems_version: 1.8.23
99
+ rubygems_version: 2.0.3
110
100
  signing_key:
111
- specification_version: 3
101
+ specification_version: 4
112
102
  summary: Morph mixin allows you to emerge class definitions via calling assignment
113
103
  methods.
114
104
  test_files: []