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

Returns a new instance of UserColumns.



352
353
354
355
# File 'lib/active_scaffold/config/core.rb', line 352

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



377
378
379
380
381
382
383
# File 'lib/active_scaffold/config/core.rb', line 377

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

Instance Method Details

#[](name) ⇒ Object



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

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

#eachObject



369
370
371
372
373
374
375
# File 'lib/active_scaffold/config/core.rb', line 369

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)


361
362
363
364
365
366
367
# File 'lib/active_scaffold/config/core.rb', line 361

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

Returns:

  • (Boolean)


386
387
388
# File 'lib/active_scaffold/config/core.rb', line 386

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