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.


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/backend/beehive_helper.rb', line 72

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


58
59
60
# File 'app/helpers/backend/beehive_helper.rb', line 58

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name


58
59
60
# File 'app/helpers/backend/beehive_helper.rb', line 58

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


58
59
60
# File 'app/helpers/backend/beehive_helper.rb', line 58

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type


58
59
60
# File 'app/helpers/backend/beehive_helper.rb', line 58

def type
  @type
end

Class Method Details

.controller_typesObject


61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/backend/beehive_helper.rb', line 61

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)

89
90
91
# File 'app/helpers/backend/beehive_helper.rb', line 89

def content?
  @has_content
end

#titleObject


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

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

#to_hashObject


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

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