Class: MegaBar::Model

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
MegaBarModelConcern
Defined in:
app/models/mega_bar/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#edit_model_displayObject

has_many :attributes #ack you can’t do this! reservedwords.herokuapp.com/words/attributes



9
10
11
# File 'app/models/mega_bar/model.rb', line 9

def edit_model_display
  @edit_model_display
end

#index_model_displayObject

has_many :attributes #ack you can’t do this! reservedwords.herokuapp.com/words/attributes



9
10
11
# File 'app/models/mega_bar/model.rb', line 9

def index_model_display
  @index_model_display
end

#model_idObject

has_many :attributes #ack you can’t do this! reservedwords.herokuapp.com/words/attributes



9
10
11
# File 'app/models/mega_bar/model.rb', line 9

def model_id
  @model_id
end

#new_model_displayObject

has_many :attributes #ack you can’t do this! reservedwords.herokuapp.com/words/attributes



9
10
11
# File 'app/models/mega_bar/model.rb', line 9

def new_model_display
  @new_model_display
end

#show_model_displayObject

has_many :attributes #ack you can’t do this! reservedwords.herokuapp.com/words/attributes



9
10
11
# File 'app/models/mega_bar/model.rb', line 9

def show_model_display
  @show_model_display
end

Instance Method Details

#make_all_filesObject



26
27
28
29
30
31
32
# File 'app/models/mega_bar/model.rb', line 26

def make_all_files
  return if ENV['mega_bar_data_loading'] == 'yes'
 # generate 'active_record:model', [self.classname]
  logger.info("creating scaffold for " + self.classname + 'via: ' + 'rails g mega_bar:mega_bar ' + self.classname + ' ' + self.id.to_s)
  system 'rails g mega_bar:mega_bar ' + self.classname + ' ' + self.id.to_s
  ActiveRecord::Migrator.migrate "db/migrate"
end

#make_model_displaysObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/mega_bar/model.rb', line 12

def make_model_displays 
  return if ENV['mega_bar_data_loading'] == 'yes'
  actions = []
  actions << {:format=>2, :action=>'new', :header=>'Create ' + self.name}  if (!ModelDisplay.by_model(self.id).by_action('new').present? && @new_model_display == 'y')
  actions << {:format=>2, :action=>'edit', :header=>'Edit ' + self.name} if (!ModelDisplay.by_model(self.id).by_action('edit').present? && @edit_model_display == 'y')
  actions << {:format=>1, :action=>'index', :header=>self.name.pluralize} if (!ModelDisplay.by_model(self.id).by_action('index').present? && @index_model_display == 'y')
  actions << {:format=>2, :action=>'show', :header=>'Show' + self.name} if (!ModelDisplay.by_model(self.id).by_action('show').present? && @show_model_display == 'y')
  log_arr = []
  actions.each do | action |
    ModelDisplay.create(:model_id=>self.id, :format=>action[:format], :action=>action[:action], :header=>action[:header])
    # log_arr  << 'format: ' + action[:format] + ', action: ' + action[:action]
  end
  logger.info 'Made model displays for:' + log_arr.join(', ')
end