Class: ForestLiana::Model::Collection

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Serialization, ActiveModel::Validations
Defined in:
app/models/forest_liana/model/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Collection

Returns a new instance of Collection.



13
14
15
16
17
18
19
# File 'app/models/forest_liana/model/collection.rb', line 13

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name}=", value)
  end

  init_properties_with_default
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def actions
  @actions
end

#fieldsObject

Returns the value of attribute fields.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def fields
  @fields
end

#iconObject

Returns the value of attribute icon.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def icon
  @icon
end

#integrationObject

Returns the value of attribute integration.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def integration
  @integration
end

#is_read_onlyObject

Returns the value of attribute is_read_only.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def is_read_only
  @is_read_only
end

#is_searchableObject

Returns the value of attribute is_searchable.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def is_searchable
  @is_searchable
end

#is_virtualObject

Returns the value of attribute is_virtual.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def is_virtual
  @is_virtual
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def name
  @name
end

#name_oldObject

Returns the value of attribute name_old.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def name_old
  @name_old
end

#only_for_relationshipsObject

Returns the value of attribute only_for_relationships.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def only_for_relationships
  @only_for_relationships
end

#pagination_typeObject

Returns the value of attribute pagination_type.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def pagination_type
  @pagination_type
end

#search_fieldsObject

Returns the value of attribute search_fields.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def search_fields
  @search_fields
end

#segmentsObject

Returns the value of attribute segments.



7
8
9
# File 'app/models/forest_liana/model/collection.rb', line 7

def segments
  @segments
end

Instance Method Details

#fields_smart_belongs_toObject



61
62
63
64
65
# File 'app/models/forest_liana/model/collection.rb', line 61

def fields_smart_belongs_to
  fields.select do |field|
    field[:'is_virtual'] && field[:type] == 'String' && !field[:reference].nil?
  end
end

#idObject



57
58
59
# File 'app/models/forest_liana/model/collection.rb', line 57

def id
  name
end

#init_properties_with_defaultObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/forest_liana/model/collection.rb', line 21

def init_properties_with_default
  @name_old ||= @name
  @is_virtual ||= false
  @icon ||= nil
  @is_read_only ||= false
  @is_searchable = true if @is_searchable.nil?
  @only_for_relationships ||= false
  @pagination_type ||= "page"
  @search_fields ||= nil
  @fields ||= []
  @actions ||= []
  @segments ||= []

  @fields = @fields.map do |field|
    field[:type] = "String" unless field.key?(:type)
    field[:default_value] = nil unless field.key?(:default_value)
    field[:enums] = nil unless field.key?(:enums)
    field[:integration] = nil unless field.key?(:integration)
    field[:is_filterable] = true unless field.key?(:is_filterable)
    field[:is_read_only] = false unless field.key?(:is_read_only)
    field[:is_required] = false unless field.key?(:is_required)
    field[:is_sortable] = true unless field.key?(:is_sortable)
    field[:is_virtual] = false unless field.key?(:is_virtual)
    field[:reference] = nil unless field.key?(:reference)
    field[:inverse_of] = nil unless field.key?(:inverse_of)
    field[:relationship] = nil unless field.key?(:relationship)
    field[:widget] = nil unless field.key?(:widget)
    field[:validations] = nil unless field.key?(:validations)
    field
  end
end

#persisted?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/forest_liana/model/collection.rb', line 53

def persisted?
  false
end

#string_smart_fields_namesObject



67
68
69
70
71
# File 'app/models/forest_liana/model/collection.rb', line 67

def string_smart_fields_names
  fields
    .select { |field| field[:'is_virtual'] && field[:type] == 'String' }
    .map { |field| field[:field].to_s }
end