Module: Mobility::Backend::ConfiguredBackend

Defined in:
lib/mobility/backend.rb

Overview

Module included in configured backend classes, which in addition to methods on the parent backend class also have a model_class and set of options.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(backend_class, model_class, options) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/mobility/backend.rb', line 236

def self.build(backend_class, model_class, options)
  Class.new(backend_class) do
    extend ConfiguredBackend

    @model_class = model_class
    configure(options) if respond_to?(:configure)
    @options = options.freeze
  end
end

.extended(klass) ⇒ Object



246
247
248
# File 'lib/mobility/backend.rb', line 246

def self.extended(klass)
  klass.singleton_class.attr_reader :options, :model_class
end

Instance Method Details

#inherited(_) ⇒ Object

Raises:



259
260
261
# File 'lib/mobility/backend.rb', line 259

def inherited(_)
  raise ConfiguredError, "Configured backends cannot be subclassed."
end

#inspectString

Show subclassed backend class name, if it has one.

Returns:

  • (String)


265
266
267
# File 'lib/mobility/backend.rb', line 265

def inspect
  (name = superclass.name) ? "#<#{name}>" : super
end

#setup_model(model_class, attribute_names) ⇒ Object

Call setup block on a class with attributes and options.

Parameters:

  • model_class

    Class to be setup-ed

  • attribute_names (Array<String>)
  • options (Hash)


254
255
256
257
# File 'lib/mobility/backend.rb', line 254

def setup_model(model_class, attribute_names)
  return unless setup_block = @setup_block
  exec_setup_block(model_class, attribute_names, options, self, &setup_block)
end