Class: ActiveScaffold::Config::Core::UserColumns

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_scaffold/config/core.rb

Constant Summary collapse

DONT_DELEGATE =
i[add exclude add_association_columns _inheritable=].freeze

Instance Method Summary collapse

Constructor Details

#initialize(columns) ⇒ UserColumns



356
357
358
359
# File 'lib/active_scaffold/config/core.rb', line 356

def initialize(columns)
  @global_columns = columns
  @columns = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



381
382
383
384
385
386
387
# File 'lib/active_scaffold/config/core.rb', line 381

def method_missing(name, ...)
  if respond_to_missing?(name, true)
    @global_columns.send(name, ...)
  else
    super
  end
end

Instance Method Details

#[](name) ⇒ Object



361
362
363
# File 'lib/active_scaffold/config/core.rb', line 361

def [](name)
  @columns[name.to_sym] || @global_columns[name]
end

#eachObject



373
374
375
376
377
378
379
# File 'lib/active_scaffold/config/core.rb', line 373

def each
  return enum_for(:each) unless block_given?

  @global_columns.each do |col|
    yield self[col.name]
  end
end

#override(name) ⇒ Object

Raises:

  • (ArgumentError)


365
366
367
368
369
370
371
# File 'lib/active_scaffold/config/core.rb', line 365

def override(name)
  raise ArgumentError, "column '#{name}' doesn't exist" unless @global_columns[name]

  (@columns[name.to_sym] ||= ActiveScaffold::DataStructures::ProxyColumn.new(@global_columns[name])).tap do |col|
    yield col if block_given?
  end
end

#respond_to_missing?(name, include_all = false) ⇒ Boolean



390
391
392
# File 'lib/active_scaffold/config/core.rb', line 390

def respond_to_missing?(name, include_all = false)
  (DONT_DELEGATE.exclude?(name) && @global_columns.respond_to?(name, include_all)) || super
end