Class: TableCloth::Base

Inherits:
Object
  • Object
show all
Includes:
Extensions::Actions, Extensions::RowAttributes
Defined in:
lib/table_cloth/base.rb

Constant Summary collapse

NoPresenterError =
Class.new(Exception)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, view) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/table_cloth/base.rb', line 10

def initialize(collection, view)
  @collection = collection
  @view       = view
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



8
9
10
# File 'lib/table_cloth/base.rb', line 8

def collection
  @collection
end

#viewObject (readonly)

Returns the value of attribute view.



8
9
10
# File 'lib/table_cloth/base.rb', line 8

def view
  @view
end

Class Method Details

.add_column(options) ⇒ Object



51
52
53
54
# File 'lib/table_cloth/base.rb', line 51

def add_column(options)
  @columns ||= {}
  @columns[options[:name]] = options
end

.column(*args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/table_cloth/base.rb', line 31

def column(*args, &block)
  options = args.extract_options! || {}
  options[:proc] = block if block_given?

  column_class = options.delete(:using) || Column

  args.each do |name|
    add_column(class: column_class, options: options, name: name)
  end
end

.columnsObject



42
43
44
45
46
47
48
49
# File 'lib/table_cloth/base.rb', line 42

def columns
  @columns ||= {}
  if superclass.respond_to? :columns
    @columns = superclass.columns.merge(@columns)
  end

  @columns
end

.configObject



56
57
58
59
60
61
62
# File 'lib/table_cloth/base.rb', line 56

def config
  @config ||= if superclass.respond_to?(:config)
    superclass.config.dup
  else
    Configuration.new
  end
end

.presenter(klass = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/table_cloth/base.rb', line 20

def presenter(klass=nil)
  return @presenter = klass if klass
  return @presenter if @presenter

  if superclass.respond_to?(:presenter)
    superclass.presenter
  else
    raise NoPresenterError, "No Presenter"
  end
end

Instance Method Details

#configObject



15
16
17
# File 'lib/table_cloth/base.rb', line 15

def config
  self.class.config
end