Class: Locomotive::Steam::ContentTypeField
- Inherits:
-
Object
- Object
- Locomotive::Steam::ContentTypeField
show all
- Includes:
- Models::Entity
- Defined in:
- lib/locomotive/steam/entities/content_type_field.rb
Defined Under Namespace
Classes: SelectOption
Instance Attribute Summary collapse
#associations, #attributes, #base_url, #localized_attributes
Instance Method Summary
collapse
#[], #[]=, #_id, #change, #method_missing, #respond_to?, #serialize
#as_json, #to_hash, #to_json
#errors, #valid?
Constructor Details
Returns a new instance of ContentTypeField.
9
10
11
12
13
14
15
16
17
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 9
def initialize(attributes = {})
super({
type: :string,
localized: false,
required: false,
unique: false,
default: nil
}.merge(attributes))
end
|
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
7
8
9
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 7
def content_type
@content_type
end
|
Instance Method Details
#association_options ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 52
def association_options
{
target_id: target_id,
inverse_of: self[:inverse_of],
order_by: order_by
}
end
|
#class_name ⇒ Object
Also known as:
target
23
24
25
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 23
def class_name
self[:class_name] || self[:target]
end
|
#is_relationship? ⇒ Boolean
60
61
62
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 60
def is_relationship?
%i(belongs_to has_many many_to_many).include?(self.type)
end
|
#localized? ⇒ Boolean
50
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 50
def localized?; self[:localized]; end
|
#order_by ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 27
def order_by
if (order_by = self[:order_by]).present?
name, direction = order_by.respond_to?(:each) ? order_by : order_by.split
{ name.to_sym => direction || 'asc' }
else
type == :has_many ? { :"position_in_#{self[:inverse_of]}" => 'asc' } : nil
end
end
|
#persisted_name ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 64
def persisted_name
case type
when :belongs_to, :select then "#{name}_id"
when :many_to_many then "#{name.singularize}_ids"
when :has_many then nil
when :password then nil
else name
end
end
|
#required? ⇒ Boolean
49
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 49
def required?; self[:required]; end
|
#target_id ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 39
def target_id
return @target_id if @target_id
@target_id = if self.target =~ Locomotive::Steam::CONTENT_ENTRY_ENGINE_CLASS_NAME
$1
else
self.target
end
end
|
#type ⇒ Object
19
20
21
|
# File 'lib/locomotive/steam/entities/content_type_field.rb', line 19
def type
self[:type].try(:to_sym)
end
|