Class: Wallaby::ActiveRecord::ModelDecorator

Inherits:
ModelDecorator show all
Defined in:
lib/adaptors/wallaby/active_record/model_decorator.rb

Defined Under Namespace

Classes: FieldsBuilder, TitleFieldFinder

Instance Attribute Summary

Attributes inherited from ModelDecorator

#model_class

Instance Method Summary collapse

Methods inherited from ModelDecorator

#initialize, #resources_name

Constructor Details

This class inherits a constructor from Wallaby::ModelDecorator

Instance Method Details

#fieldsObject



2
3
4
5
6
7
8
9
10
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 2

def fields
  @fields ||= {}.tap do |hash|
    if model_class.table_exists?
      hash.merge! general_fields
      hash.merge! association_fields
      hash.except! *foreign_keys_from_associations
    end
  end.with_indifferent_access
end

#form_active_errors(resource) ⇒ Object



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

def form_active_errors(resource)
  resource.errors
end

#form_field_namesObject



31
32
33
34
35
36
37
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 31

def form_field_names
  @form_field_names ||= form_fields.reject do |field_name, |
    %W( #{ primary_key } updated_at created_at ).include?(field_name) ||
    [:has_scope] ||
    [:is_through]
  end.keys
end

#form_fieldsObject



20
21
22
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 20

def form_fields
  @form_fields  ||= fields.deep_dup
end

#guess_title(resource) ⇒ Object



47
48
49
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 47

def guess_title(resource)
  resource.public_send title_field_finder.find
end

#index_field_namesObject



24
25
26
27
28
29
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 24

def index_field_names
  @index_field_names ||= index_fields.reject do |field_name, |
    [:is_association] ||
    %w( binary citext hstore json jsonb text tsvector xml ).include?([:type])
  end.keys
end

#index_fieldsObject



12
13
14
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 12

def index_fields
  @index_fields ||= fields.deep_dup
end

#primary_keyObject



43
44
45
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 43

def primary_key
  @model_class.primary_key
end

#show_fieldsObject



16
17
18
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 16

def show_fields
  @show_fields  ||= fields.deep_dup
end