Class: SimplePrivateMessages::Generators::ModelGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/simple_private_messages/model/model_generator.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) plural_camel_case_name (readonly)

Returns the value of attribute plural_camel_case_name



14
15
16
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 14

def plural_camel_case_name
  @plural_camel_case_name
end

- (Object) plural_camel_case_parent (readonly)

Returns the value of attribute plural_camel_case_parent



15
16
17
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 15

def plural_camel_case_parent
  @plural_camel_case_parent
end

- (Object) plural_lower_case_name (readonly)

Returns the value of attribute plural_lower_case_name



14
15
16
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 14

def plural_lower_case_name
  @plural_lower_case_name
end

- (Object) plural_lower_case_parent (readonly)

Returns the value of attribute plural_lower_case_parent



15
16
17
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 15

def plural_lower_case_parent
  @plural_lower_case_parent
end

- (Object) singular_camel_case_name (readonly)

Returns the value of attribute singular_camel_case_name



14
15
16
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 14

def singular_camel_case_name
  @singular_camel_case_name
end

- (Object) singular_camel_case_parent (readonly)

Returns the value of attribute singular_camel_case_parent



15
16
17
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 15

def singular_camel_case_parent
  @singular_camel_case_parent
end

- (Object) singular_lower_case_name (readonly)

Returns the value of attribute singular_lower_case_name



14
15
16
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 14

def singular_lower_case_name
  @singular_lower_case_name
end

- (Object) singular_lower_case_parent (readonly)

Returns the value of attribute singular_lower_case_parent



15
16
17
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 15

def singular_lower_case_parent
  @singular_lower_case_parent
end

Class Method Details

+ (Object) next_migration_number(dirname)

Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb



23
24
25
26
27
28
29
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 23

def self.next_migration_number(dirname) #:nodoc:
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

+ (Object) source_root



17
18
19
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 17

def self.source_root
   	File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

- (Object) go



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/simple_private_messages/model/model_generator.rb', line 31

def go
    @singular_camel_case_name = message_model_name.singularize.camelize
    @plural_camel_case_name = message_model_name.pluralize.camelize
    @singular_lower_case_name = message_model_name.singularize.underscore
    @plural_lower_case_name = message_model_name.pluralize.underscore

    @singular_camel_case_parent = user_model_name.singularize.camelize
    @plural_camel_case_parent = user_model_name.pluralize.camelize
    @singular_lower_case_parent = user_model_name.singularize.underscore
   	@plural_lower_case_parent = user_model_name.pluralize.underscore    
	
	#directory "app/models"
	template "model.rb", "app/models/#{singular_lower_case_name}.rb"
		
	migration_template "migration.rb", "db/migrate/create_#{plural_lower_case_name}", :assigns => {
		:migration_name => "Create#{plural_camel_case_name}"
	}
end