Module: Cream::GeneratorHelper::Orm

Defined in:
lib/generators/cream/helpers/orm_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_recordObject



24
25
26
# File 'lib/generators/cream/helpers/orm_helper.rb', line 24

def active_record
  [:ar, :active_record]
end

#data_mapperObject



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

def data_mapper
  [:dm, :data_mapper]
end

#get_orm(name) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/cream/helpers/orm_helper.rb', line 52

def get_orm name
  return :active_record if is_active_record? name 
  return :mongo_mapper if is_mongo_mapper? name
  return :data_mapper if is_data_mapper? name

  return :couch_db  if name == :couch_db
  return :mongoid   if name == :mongoid
  
  raise ArgumentError, "ERROR: Cream does not currently support the orm: #{name}"
end

#is_active_record?(name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/generators/cream/helpers/orm_helper.rb', line 28

def is_active_record? name 
  active_record.include? name
end

#is_data_mapper?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def is_data_mapper? name 
  data_mapper.include? name
end

#is_default_devise_orm?Boolean

Returns:

  • (Boolean)


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

def is_default_devise_orm?
  [:active_record, :mongoid].include? orm
end

#is_mongo_mapper?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/generators/cream/helpers/orm_helper.rb', line 36

def is_mongo_mapper? name 
  mongo_mapper.include? name
end

#mongo_mapperObject



32
33
34
# File 'lib/generators/cream/helpers/orm_helper.rb', line 32

def mongo_mapper
  [:mm, :mongo_mapper]
end

#ormObject



12
13
14
# File 'lib/generators/cream/helpers/orm_helper.rb', line 12

def orm
  @orm ||= get_orm options[:orm].to_s.underscore.to_sym
end

#valid_ormsObject



20
21
22
# File 'lib/generators/cream/helpers/orm_helper.rb', line 20

def valid_orms
  active_record + data_mapper + mongo_mapper + [:couch_db, :mongoid]
end

#valid_orms_listObject



16
17
18
# File 'lib/generators/cream/helpers/orm_helper.rb', line 16

def valid_orms_list
  valid_orms.map(&:to_s).join(', ')
end

#validate_ormObject



4
5
6
7
8
9
10
# File 'lib/generators/cream/helpers/orm_helper.rb', line 4

def validate_orm
   if !valid_orms.include?(orm)
     say "ERROR: ORM #{orm} is not currently supported. Please use one of: #{valid_orms_list}", :red
     return false
   end
   true
end