Module: Bento::Generators::OrmHelpers

Included in:
ActiveRecord::Generators::BentoGenerator
Defined in:
lib/generators/bento/orm_helpers.rb

Instance Method Summary collapse

Instance Method Details

#bento_membership_exists?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/generators/bento/orm_helpers.rb', line 55

def bento_membership_exists?
  File.exists?(File.join(destination_root, bento_membership_path))
end

#bento_membership_model_contentObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/bento/orm_helpers.rb', line 40

def bento_membership_model_content
"class BentoMembership < ActiveRecord::Base\n  belongs_to :user\n  belongs_to :\#{class_name.underscore}\n\n  attr_accessible :\#{class_name.underscore}_id, :user_id\nend\n"
end

#bento_membership_pathObject



63
64
65
# File 'lib/generators/bento/orm_helpers.rb', line 63

def bento_membership_path
  @bento_membership_path ||= File.join("app", "models", "bento_membership.rb")
end

#model_contentsObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/generators/bento/orm_helpers.rb', line 4

def model_contents
"  # Include all bento modules. Others available are:\n  # :all, :validations, :user_accessors, :user_association, :user_accessors, :trial\n  bento\n\n  # Setup accessible (or protected) attributes for your model\n  attr_accessible :name\n"
end

#model_exists?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/generators/bento/orm_helpers.rb', line 51

def model_exists?
  File.exists?(File.join(destination_root, model_path))
end

#model_pathObject



59
60
61
# File 'lib/generators/bento/orm_helpers.rb', line 59

def model_path
  @model_path ||= File.join("app", "models", "#{file_path}.rb")
end

#user_model_contentObject



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/bento/orm_helpers.rb', line 15

def user_model_content
"  has_many :bento_memberships\n  has_many :\#{table_name}, :through => :bento_memberships\n\n  #\n  # Remove this method call unless you want to work with\n  # the has_many :through association as if it was a simple\n  # belongs_to :\#{class_name.underscore}.\n  #\n  # If you know for sure that you don't want to be able\n  # to have users that belongs to several \#{table_name} you\n  # can of course edit the generated migration files to\n  # not create the join model table \"bento_memberships\" and instead\n  # add a \#{class_name.underscore}_id to your User model.\n  #\n  # You also need to not use the :user_association module in bento\n  # for example to use all in your \#{class_name} model change the\n  # call to bento from `bento :all` to bento `:validations, :user_accessors, :user_accessors, :trial`\n  # then you just remove the above relations and remove the \"fake_\" part below.\n  #\n  fake_belongs_to :\#{class_name.underscore}\n"
end

#user_pathObject



67
68
69
# File 'lib/generators/bento/orm_helpers.rb', line 67

def user_path
  @user_path ||= File.join("app", "models", "user.rb")
end