Module: Rails3Generators::Helpers::Model

Defined in:
lib/generators/helpers/model_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#model_attributesObject

Returns the value of attribute model_attributes.



5
6
7
# File 'lib/generators/helpers/model_helper.rb', line 5

def model_attributes
  @model_attributes
end

#model_indexesObject

Returns the value of attribute model_indexes.



5
6
7
# File 'lib/generators/helpers/model_helper.rb', line 5

def model_indexes
  @model_indexes
end

Instance Method Details

#arg_name(arg) ⇒ Object



40
41
42
# File 'lib/generators/helpers/model_helper.rb', line 40

def arg_name(arg)
  arg.split(':').first        
end

#arg_type(arg) ⇒ Object



44
45
46
# File 'lib/generators/helpers/model_helper.rb', line 44

def arg_type(arg)
  arg.split(':')[1] || 'string'
end

#class_nameObject



64
65
66
# File 'lib/generators/helpers/model_helper.rb', line 64

def class_name
  model_name.camelize
end

#model_exists?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/generators/helpers/model_helper.rb', line 52

def model_exists?
  File.exist? destination_path("app/models/#{singular_name}.rb")
end

#model_nameObject



48
49
50
# File 'lib/generators/helpers/model_helper.rb', line 48

def model_name
  name
end

#parse_model_attributes(with_indexes = true) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/helpers/model_helper.rb', line 7

def parse_model_attributes(with_indexes = true)
  @model_attributes = []        
  @model_indexes = {}
  # 
  # attributes.each do |arg|
  #   if with_indexes
  #     # extract index markers
  #     if arg.include?('#')  
  #       arg.gsub! /#.*$/, ''            
  #       model_indexes[arg_name(arg).to_sym] = true
  #     end
  #   end
  # 
  #   if arg.include?(':')
  #     model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
  #   else
  #     model_attributes << Rails::Generators::GeneratedAttribute.new(arg, "string")            
  #   end
  # 
  #   model_attributes.uniq!
  # 
  #   if model_attributes.empty?
  #     if model_exists?
  #       model_columns_for_attributes.each do |column|
  #         model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
  #       end
  #     else
  #       model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
  #     end
  #   end
  # end 
end

#plural_class_nameObject



68
69
70
# File 'lib/generators/helpers/model_helper.rb', line 68

def plural_class_name
  plural_name.camelize
end

#plural_nameObject



60
61
62
# File 'lib/generators/helpers/model_helper.rb', line 60

def plural_name
  model_name.underscore.pluralize
end

#singular_nameObject



56
57
58
# File 'lib/generators/helpers/model_helper.rb', line 56

def singular_name
  model_name.underscore
end