Class: Backend::BeehiveHelper::Beehive::Cell

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/backend/beehive_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Cell

Returns a new instance of Cell.


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/helpers/backend/beehive_helper.rb', line 77

def initialize(name, options = {})
  unless name.is_a?(Symbol)
    raise 'Only symbol for cell name. Use :title option to specify title.'
  end
  @name = name.to_sym
  @options = options
  @type = @options.delete(:type) || @name
  @has_content = @options.key?(:content)
  @content = @options.delete(:content)
  @i18n = @options.delete(:i18n) || @options
  if self.class.controller_types.include?(@type)
    raise "Local type cannot be: #{@type}. Already taken." if content?
  elsif !content?
    raise "Invalid cell. Need content or a valid controller cell name (Not #{@name} alone)"
  end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content


63
64
65
# File 'app/helpers/backend/beehive_helper.rb', line 63

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name


63
64
65
# File 'app/helpers/backend/beehive_helper.rb', line 63

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


63
64
65
# File 'app/helpers/backend/beehive_helper.rb', line 63

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type


63
64
65
# File 'app/helpers/backend/beehive_helper.rb', line 63

def type
  @type
end

Class Method Details

.controller_typesObject


66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/backend/beehive_helper.rb', line 66

def self.controller_types
  unless @controller_types
    Dir.chdir(Rails.root.join('app/controllers/backend/cells')) do
      @controller_types = Dir['*_cells_controller.rb'].map do |path|
        path.gsub(/_cells_controller.rb$/, '').to_sym
      end.compact
    end
  end
  @controller_types
end

Instance Method Details

#content?Boolean

Returns:

  • (Boolean)

94
95
96
# File 'app/helpers/backend/beehive_helper.rb', line 94

def content?
  @has_content
end

#titleObject


98
99
100
# File 'app/helpers/backend/beehive_helper.rb', line 98

def title
  @options[:title].is_a?(Symbol) ? @options[:title].tl(@i18n) : (@options[:title] || @name.tl(@i18n))
end

#to_hashObject


102
103
104
# File 'app/helpers/backend/beehive_helper.rb', line 102

def to_hash
  { name: @name.to_s, type: @type.to_s, options: @options }
end