Class: MegaBar::Block

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#edit_model_displayObject

Returns the value of attribute edit_model_display.



14
15
16
# File 'app/models/mega_bar/block.rb', line 14

def edit_model_display
  @edit_model_display
end

#index_model_displayObject

Returns the value of attribute index_model_display.



14
15
16
# File 'app/models/mega_bar/block.rb', line 14

def index_model_display
  @index_model_display
end

#model_idObject

Returns the value of attribute model_id.



14
15
16
# File 'app/models/mega_bar/block.rb', line 14

def model_id
  @model_id
end

#new_model_displayObject

Returns the value of attribute new_model_display.



14
15
16
# File 'app/models/mega_bar/block.rb', line 14

def new_model_display
  @new_model_display
end

#show_model_displayObject

Returns the value of attribute show_model_display.



14
15
16
# File 'app/models/mega_bar/block.rb', line 14

def show_model_display
  @show_model_display
end

Class Method Details

.by_actions(action) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/mega_bar/block.rb', line 18

def self.by_actions(action)
  if action.present?
    case action
    when 'show'
      where(actions: ['all', 'sine', 'show', 'current'])
    when 'index'
      where(actions: ['all', 'sine', 'index', 'current'])
    when 'new'
      where(actions: ['all', 'sine', 'new', 'current'])
    when 'edit'
      where(actions: ['all', 'sine', 'edit', 'current'])
    when 'create'
      where(actions: ['all', 'current'])
    when 'update'
      where(actions: ['all', 'current'])
    when 'destroy'
      where(actions: ['all', 'current'])
    else
      where(actions: ['all', 'current', action])
    end
  end
end

Instance Method Details

#make_model_displaysObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/mega_bar/block.rb', line 41

def make_model_displays
  if (!self.model_id.nil? && !self.model_id.to_s.empty? && Integer(self.model_id) > 0)
    model_name = Model.find(self.model_id).name
    actions = []
    actions << {:format=>2, :action=>'new', :header=>'Create ' + model_name.humanize.singularize, collection_or_member: 'member'}  if (!ModelDisplay.by_block(self.id).by_action('new').present? && @new_model_display == 'y')
    actions << {:format=>2, :action=>'edit', :header=>'Edit ' + model_name.humanize.singularize,  collection_or_member: 'member'} if (!ModelDisplay.by_block(self.id).by_action('edit').present? && @edit_model_display == 'y')
    actions << {:format=>1, :action=>'index', :header=>model_name.humanize.pluralize,  collection_or_member: 'collection'} if (!ModelDisplay.by_block(self.id).by_action('index').present? && @index_model_display == 'y')
    actions << {:format=>2, :action=>'show', :header=>model_name.humanize.singularize,  collection_or_member: 'member'} if (!ModelDisplay.by_block(self.id).by_action('show').present? && @show_model_display == 'y')
    actions.each do | action |
      md = ModelDisplay.create(:block_id=>self.id, model_id: self.model_id, :format=>action[:format], :action=>action[:action], :header=>action[:header], collection_or_member: action[:collection_or_member])
    end
  end

end