module OptAR::OptimalAR::Builder::ClassMethods

Public Instance Methods

build_optar(name, options = {}) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 8
def build_optar(name, options = {})
  validate_name(name)
  validate_scope(options[:scope]) if options[:scope]
  faker_proc = lambda do |*args|
    fetch_optar_objects(options[:scope], options)
  end
  singleton_class.send(:redefine_method, name, &faker_proc)
end
Also aliased as: swindle, show_as
show_as(name, options = {})
Alias for: build_optar
swindle(name, options = {})
Alias for: build_optar

Private Instance Methods

fetch_default_scoped_optars(options) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 58
def fetch_default_scoped_optars(options)
  send(:build_default_scope).optars(options)
end
fetch_optar_objects(scope, options) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 46
def fetch_optar_objects(scope, options)
  if scope
    fetch_scoped_optar(scope, options)
  else
    fetch_default_scoped_optars(options)
  end
end
fetch_scoped_optar(scope, options) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 54
def fetch_scoped_optar(scope, options)
  send(scope).optars(options)
end
invalid_name(options) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 72
def invalid_name(options)
  error_options = "#{options[:name]} :: #{options[:type]}"
  msg = " :: swindle defined with invalid name :: #{error_options}"
  OptAR::Logger.log(msg, :error)
  OptAR::Errors::DuplicateNameError.new(options)
end
throw_error(error_type, error_options) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 62
def throw_error(error_type, error_options)
  raise send(error_type, error_options)
end
undefined_scope(options) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 66
def undefined_scope(options)
  msg = " :: swindle defined with Undefined Scope :: #{options[:scope]}"
  OptAR::Logger.log(msg, :error)
  OptAR::Errors::UndefinedScopeError.new(options)
end
valid_name?(name) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 38
def valid_name?(name)
  if respond_to? name
    :duplicate_name
  else
    true
  end
end
valid_scope?(scope_name) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 28
def valid_scope?(scope_name)
  respond_to? scope_name
end
validate_name(name) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 32
def validate_name(name)
  valid = valid_name?(name)
  return true if valid == true
  throw_error(:invalid_name, name: name, type: valid)
end
validate_scope(scope_name) click to toggle source
# File lib/opt_ar/optimal_ar/builder.rb, line 22
def validate_scope(scope_name)
  valid = valid_scope?(scope_name)
  return if valid == true
  throw_error(:undefined_scope, scope: scope_name)
end