Class: Wallaby::Map

Inherits:
Object
  • Object
show all
Extended by:
Classifier
Defined in:
lib/wallaby/map.rb,
lib/services/wallaby/map/mode_mapper.rb,
lib/services/wallaby/map/model_class_mapper.rb

Overview

All the lookups that Wallaby needs.

Defined Under Namespace

Classes: ModeMapper, ModelClassMapper

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Classifier

class_name_of, to_class

Class Attribute Details

.class_name_error_mapObject (readonly)

Cache the class name error



108
109
110
# File 'lib/wallaby/map.rb', line 108

def class_name_error_map
  @class_name_error_map ||= {}
end

.modesArray<String>

Returns all Wallaby::Modes.

Returns:



14
15
16
# File 'lib/wallaby/map.rb', line 14

def modes
  @modes ||= ClassArray.new Mode.descendants
end

Class Method Details

.authorizer_provider_map(model_class) ⇒ Class

{ model => authorizer_provider }

Parameters:

  • model_class (Class)

Returns:

  • (Class)

    model authorizer provider class



87
88
89
90
# File 'lib/wallaby/map.rb', line 87

def authorizer_provider_map(model_class)
  @authorizer_provider_map ||= ClassHash.new
  @authorizer_provider_map[model_class] ||= mode_map[model_class].try :model_authorization_providers
end

.clearObject

Reset all the instance variables to nil



115
116
117
# File 'lib/wallaby/map.rb', line 115

def clear
  instance_variables.each { |name| instance_variable_set name, nil }
end

.id_regexpRegexp

Returns regexp to match data for param ‘:id`.

Returns:

  • (Regexp)

    regexp to match data for param ‘:id`



100
101
102
# File 'lib/wallaby/map.rb', line 100

def id_regexp
  @id_regexp ||= IdRegexp.new.execute
end

.mode_mapClassHash

Returns { Model Class => Wallaby::Mode }.

Returns:



19
20
21
22
23
24
25
# File 'lib/wallaby/map.rb', line 19

def mode_map
  @mode_map ||= begin
    # NOTE: this is the point where all model files should be required
    Preloader.require_models
    ModeMapper.execute(modes).freeze
  end
end

.model_class_map(resources_name, value = nil) ⇒ Class

{ resources name => model } It’s a setter when value is given. Otherwise, a getter.

Parameters:

  • resources_name (String)

Returns:

  • (Class)


48
49
50
51
# File 'lib/wallaby/map.rb', line 48

def model_class_map(resources_name, value = nil)
  @model_class_map ||= ClassHash.new
  @model_class_map[resources_name] ||= value || Classifier.to_class(Inflector.to_model_name(resources_name))
end

.model_classesObject

Deprecated.


28
29
30
# File 'lib/wallaby/map.rb', line 28

def model_classes
  Deprecator.alert method(__callee__), from: '0.3.0'
end

.model_decorator_map(model_class, application_decorator) ⇒ ModelDecorator

{ model => model decorator }

Parameters:

  • model_class (Class)
  • application_decorator (Class)

Returns:



59
60
61
62
63
64
# File 'lib/wallaby/map.rb', line 59

def model_decorator_map(model_class, application_decorator)
  @model_decorator_map ||= ClassHash.new
  @model_decorator_map[application_decorator] ||= ClassHash.new
  @model_decorator_map[application_decorator][model_class] ||=
    mode_map[model_class].try(:model_decorator).try :new, model_class
end

.pagination_provider_map(model_class) ⇒ Class

{ model => pagination_provider }

Parameters:

  • model_class (Class)

Returns:

  • (Class)

    model pagination provider class



79
80
81
82
# File 'lib/wallaby/map.rb', line 79

def pagination_provider_map(model_class)
  @pagination_provider_map ||= ClassHash.new
  @pagination_provider_map[model_class] ||= mode_map[model_class].try :model_pagination_provider
end

.resources_name_map(model_class, value = nil) ⇒ String

{ model => resources name } It’s a setter when value is given. Otherwise, a getter.

Parameters:

  • model_class (Class)
  • value (String, nil) (defaults to: nil)

    resources name

Returns:

  • (String)

    resources name



38
39
40
41
# File 'lib/wallaby/map.rb', line 38

def resources_name_map(model_class, value = nil)
  @resources_name_map ||= ClassHash.new
  @resources_name_map[model_class] ||= value || Inflector.to_resources_name(model_class)
end

.resources_regexpRegexp

Returns regexp to match data for param ‘:resources`.

Returns:

  • (Regexp)

    regexp to match data for param ‘:resources`



95
96
97
# File 'lib/wallaby/map.rb', line 95

def resources_regexp
  @resources_regexp ||= ResourcesRegexp.new.execute
end

.service_provider_map(model_class) ⇒ Class

{ model => service_provider }

Parameters:

  • model_class (Class)

Returns:

  • (Class)

    model service provider instance



71
72
73
74
# File 'lib/wallaby/map.rb', line 71

def service_provider_map(model_class)
  @service_provider_map ||= ClassHash.new
  @service_provider_map[model_class] ||= mode_map[model_class].try :model_service_provider
end