medea-generators 0.3.0 → 0.4.0

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.
@@ -4,7 +4,7 @@ require 'rails/generators/generated_attribute'
4
4
  module Medea
5
5
  module Generators
6
6
  class ScaffoldGenerator < Base
7
- no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions }
7
+ no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions, :list_properties }
8
8
 
9
9
  argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
10
10
  argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
@@ -26,15 +26,25 @@ module Medea
26
26
 
27
27
  @controller_actions = []
28
28
  @model_attributes = []
29
+ @list_properties = {}
29
30
  @skip_model = options.skip_model?
30
31
  @namespace_model = options.namespace_model?
31
32
  @invert_actions = options.invert?
32
33
 
34
+ list_types = %w(has owns)
33
35
  args_for_c_m.each do |arg|
34
36
  if arg == '!'
35
37
  @invert_actions = true
36
38
  elsif arg.include?(':')
37
- @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
39
+ list = arg.split(':')
40
+ #if the argument is a "has" or a "owns", we treat it as a list property.
41
+ #Otherwise, it's a regular model attribute
42
+ if list_types.include? list[0]
43
+ @list_properties[list[0]] ||= []
44
+ @list_properties[list[0]] << list[1..2]
45
+ else
46
+ @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
47
+ end
38
48
  else
39
49
  @controller_actions << arg
40
50
  @controller_actions << 'create' if arg == 'new'
@@ -49,6 +59,7 @@ module Medea
49
59
  @controller_actions = all_actions - @controller_actions
50
60
  end
51
61
 
62
+ #we don't do anything differently if there are no attributes passed.
52
63
  if @model_attributes.empty?
53
64
  if model_exists?
54
65
  model_columns_for_attributes.each do |column|
@@ -66,7 +77,7 @@ module Medea
66
77
  end
67
78
 
68
79
  def create_model
69
- template 'model.rb', "app/models/#{model_path}.rb"
80
+ template 'model.rb.erb', "app/models/#{model_path}.rb"
70
81
  if test_framework == :rspec
71
82
  template "tests/rspec/model.rb", "spec/models/#{model_path}_spec.rb"
72
83
  template 'fixtures.yml', "spec/fixtures/#{model_path.pluralize}.yml"
@@ -254,10 +265,13 @@ module Medea
254
265
  end
255
266
  end
256
267
 
268
+ def model_list_properties
269
+ class_name.constantize
270
+
271
+ end
272
+
257
273
  def model_columns_for_attributes
258
- class_name.constantize.columns.reject do |column|
259
- column.name.to_s =~ /^(id|created_at|updated_at)$/
260
- end
274
+ []
261
275
  end
262
276
 
263
277
  def view_language
@@ -0,0 +1,13 @@
1
+ class <%= class_name %> < Medea::JasonObject
2
+ <%
3
+ result = []
4
+ ["has", "owns"].each do |l|
5
+ if list_properties[l]
6
+ list_properties[l].each do |a|
7
+ result << "#{l}_many :#{a[0]}, #{a[1]}"
8
+ end
9
+ end
10
+ end
11
+ %>
12
+ <%= result.join("\n ") if result.count > 0 %>
13
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "medea-generators"
6
- s.version = "0.3.0"
6
+ s.version = "0.4.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Michael Jensen"]
9
9
  s.email = ["michaelj@jasondb.com"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Jensen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-21 00:00:00 +11:00
17
+ date: 2011-01-24 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -92,7 +92,7 @@ files:
92
92
  - lib/generators/medea/scaffold/templates/controller.rb
93
93
  - lib/generators/medea/scaffold/templates/fixtures.yml
94
94
  - lib/generators/medea/scaffold/templates/helper.rb
95
- - lib/generators/medea/scaffold/templates/model.rb
95
+ - lib/generators/medea/scaffold/templates/model.rb.erb
96
96
  - lib/generators/medea/scaffold/templates/tests/rspec/actions/create.rb
97
97
  - lib/generators/medea/scaffold/templates/tests/rspec/actions/destroy.rb
98
98
  - lib/generators/medea/scaffold/templates/tests/rspec/actions/edit.rb
@@ -1,3 +0,0 @@
1
- class <%= class_name %> < Medea::JasonObject
2
-
3
- end