Class: TableCloth::Base

Inherits:
Object
  • Object
show all
Includes:
Extensions::Actions
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.



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

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

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Class Method Details

.add_column(options) ⇒ Object



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

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

.column(*args, &block) ⇒ Object



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

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



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

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

  @columns
end

.configObject



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

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

.presenter(klass = nil) ⇒ Object



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

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



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

def config
  self.class.config
end