Class: Wallaby::ActiveRecord::ModelDecorator
Defined Under Namespace
Classes: FieldsBuilder, TitleFieldFinder
Instance Attribute Summary
#model_class
Instance Method Summary
collapse
#initialize, #resources_name
Instance Method Details
#fields ⇒ Object
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
|
39
40
41
|
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 39
def form_active_errors(resource)
resource.errors
end
|
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, metadata|
%W( #{ primary_key } updated_at created_at ).include?(field_name) ||
metadata[:has_scope] ||
metadata[:is_through]
end.keys
end
|
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_names ⇒ Object
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, metadata|
metadata[:is_association] ||
%w( binary citext hstore json jsonb text tsvector xml ).include?(metadata[:type])
end.keys
end
|
#index_fields ⇒ Object
12
13
14
|
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 12
def index_fields
@index_fields ||= fields.deep_dup
end
|
#primary_key ⇒ Object
43
44
45
|
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 43
def primary_key
@model_class.primary_key
end
|
#show_fields ⇒ Object
16
17
18
|
# File 'lib/adaptors/wallaby/active_record/model_decorator.rb', line 16
def show_fields
@show_fields ||= fields.deep_dup
end
|