Class: Wallaby::ModelDecorator

Inherits:
Object
  • Object
show all
Includes:
FieldHelpers
Defined in:
lib/interfaces/wallaby/model_decorator.rb,
lib/interfaces/wallaby/model_decorator/field_helpers.rb

Direct Known Subclasses

ActiveRecord::ModelDecorator

Defined Under Namespace

Modules: FieldHelpers

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FieldHelpers

#form_label_of, #form_metadata_of, #form_type_of, #index_label_of, #index_metadata_of, #index_type_of, #label_of, #metadata_of, #show_label_of, #show_metadata_of, #show_type_of, #type_of

Constructor Details

#initialize(model_class) ⇒ ModelDecorator

Returns a new instance of ModelDecorator.



11
12
13
# File 'lib/interfaces/wallaby/model_decorator.rb', line 11

def initialize(model_class)
  @model_class = model_class
end

Instance Attribute Details

#field_namesArray

Returns field names.

Returns:

  • (Array)

    field names



27
28
29
# File 'lib/interfaces/wallaby/model_decorator.rb', line 27

def field_names
  @field_names ||= reposition fields.keys, primary_key
end

#form_field_namesArray

Returns field names of form page.

Returns:

  • (Array)

    field names of form page



78
79
80
# File 'lib/interfaces/wallaby/model_decorator.rb', line 78

def form_field_names
  @form_field_names ||= reposition form_fields.keys, primary_key
end

#index_field_namesArray

Returns field names of index page.

Returns:

  • (Array)

    field names of index page



44
45
46
# File 'lib/interfaces/wallaby/model_decorator.rb', line 44

def index_field_names
  @index_field_names ||= reposition index_fields.keys, primary_key
end

#model_classObject (readonly)

Returns the value of attribute model_class.



7
8
9
# File 'lib/interfaces/wallaby/model_decorator.rb', line 7

def model_class
  @model_class
end

#show_field_namesArray

Returns field names of show page.

Returns:

  • (Array)

    field names of show page



61
62
63
# File 'lib/interfaces/wallaby/model_decorator.rb', line 61

def show_field_names
  @show_field_names ||= reposition show_fields.keys, primary_key
end

Instance Method Details

#fieldsHash

Returns metadata information for all fields that index/show/form will copy.

Returns:

  • (Hash)

    metadata information for all fields that index/show/form will copy

Raises:



17
18
19
# File 'lib/interfaces/wallaby/model_decorator.rb', line 17

def fields
  raise NotImplemented
end

#fields=(fields) ⇒ Object

Parameters:

  • fields (Hash)

    metadata information for all fields



22
23
24
# File 'lib/interfaces/wallaby/model_decorator.rb', line 22

def fields=(fields)
  @fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
end

#filtersHash

Returns custom filters.

Returns:

  • (Hash)

    custom filters



83
84
85
# File 'lib/interfaces/wallaby/model_decorator.rb', line 83

def filters
  @filters ||= ::ActiveSupport::HashWithIndifferentAccess.new
end

#form_active_errors(_resource) ⇒ Hash

Returns errors.

Returns:

  • (Hash)

    errors

Raises:



88
89
90
# File 'lib/interfaces/wallaby/model_decorator.rb', line 88

def form_active_errors(_resource)
  raise NotImplemented
end

#form_fieldsHash

Returns metadata information for all fields that would be used on form page.

Returns:

  • (Hash)

    metadata information for all fields that would be used on form page

Raises:



67
68
69
# File 'lib/interfaces/wallaby/model_decorator.rb', line 67

def form_fields
  raise NotImplemented
end

#form_fields=(fields) ⇒ Object

Parameters:

  • fields (Hash)

    metadata information for all fields that would be used on form page



73
74
75
# File 'lib/interfaces/wallaby/model_decorator.rb', line 73

def form_fields=(fields)
  @form_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
end

#guess_title(_resource) ⇒ String

Returns title of given resource.

Parameters:

  • _resource (Object)

    resource

Returns:

  • (String)

    title of given resource

Raises:



99
100
101
# File 'lib/interfaces/wallaby/model_decorator.rb', line 99

def guess_title(_resource)
  raise NotImplemented
end

#index_fieldsHash

Returns metadata information for all fields that would be used on index page.

Returns:

  • (Hash)

    metadata information for all fields that would be used on index page

Raises:



33
34
35
# File 'lib/interfaces/wallaby/model_decorator.rb', line 33

def index_fields
  raise NotImplemented
end

#index_fields=(fields) ⇒ Object

Parameters:

  • fields (Hash)

    metadata information for all fields that would be used on index page



39
40
41
# File 'lib/interfaces/wallaby/model_decorator.rb', line 39

def index_fields=(fields)
  @index_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
end

#primary_keyString

Returns primary key.

Returns:

  • (String)

    primary key

Raises:



93
94
95
# File 'lib/interfaces/wallaby/model_decorator.rb', line 93

def primary_key
  raise NotImplemented
end

#resources_nameString

Returns resources name mapped from model class.

Returns:

  • (String)

    resources name mapped from model class



104
105
106
# File 'lib/interfaces/wallaby/model_decorator.rb', line 104

def resources_name
  Map.resources_name_map @model_class
end

#show_fieldsHash

Returns metadata information for all fields that would be used on show page.

Returns:

  • (Hash)

    metadata information for all fields that would be used on show page

Raises:



50
51
52
# File 'lib/interfaces/wallaby/model_decorator.rb', line 50

def show_fields
  raise NotImplemented
end

#show_fields=(fields) ⇒ Object

Parameters:

  • fields (Hash)

    metadata information for all fields that would be used on show page



56
57
58
# File 'lib/interfaces/wallaby/model_decorator.rb', line 56

def show_fields=(fields)
  @show_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
end