Class: Tableling::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tableling-rails/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}, &block) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tableling-rails/config.rb', line 7

def initialize model, options = {}, &block

  @model = model
  @views = []

  @settings = Settings.new Tableling.settings
  extend @settings.dsl

  instance_eval &block if block
  @frozen = true
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/tableling-rails/config.rb', line 5

def model
  @model
end

#settingsObject (readonly)

Returns the value of attribute settings.



5
6
7
# File 'lib/tableling-rails/config.rb', line 5

def settings
  @settings
end

Instance Method Details

#default_view(options = {}, &block) ⇒ Object



25
26
27
# File 'lib/tableling-rails/config.rb', line 25

def default_view options = {}, &block
  view :default, options, &block
end

#process(params) ⇒ Object

Raises:



29
30
31
32
# File 'lib/tableling-rails/config.rb', line 29

def process params
  raise ConfigurationError, "You must specify a default view" unless view(:default)
  view(:default).process params
end

#view(name, options = {}, &block) ⇒ Object



19
20
21
22
23
# File 'lib/tableling-rails/config.rb', line 19

def view name, options = {}, &block
  return @views.find{ |v| v.name.to_s == name.to_s } if @frozen
  @views.delete_if{ |v| v.name.to_s == name }
  View.new(name, self, options, &block).tap{ |v| @views << v }
end