Class: ForestLiana::Model::Action

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Action



10
11
12
13
14
15
16
17
18
19
20
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/forest_liana/model/action.rb', line 10

def initialize(attributes = {})
  if attributes.key?(:global)
    FOREST_LOGGER.error "REMOVED OPTION: The support for Smart Action \"global\" option is now " \
      "removed. Please set \"type: 'global'\" instead of \"global: true\" for the " \
      "\"#{attributes[:name]}\" Smart Action."
  end


  if attributes.key?(:type) && !['bulk', 'global', 'single'].include?(attributes[:type])
    FOREST_LOGGER.warn "Please set a valid Smart Action type (\"bulk\", \"global\" or " \
      "\"single\") for the \"#{attributes[:name]}\" Smart Action."
  end

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

  @fields ||= []

  has_fields_without_name = false

  @fields.delete_if do |field|
    if field.key?(:field)
      false
    else
      has_fields_without_name = true
      true
    end
  end

  @fields.map! do |field|
    if field.key?(:isRequired)
      FOREST_LOGGER.warn "DEPRECATION WARNING: isRequired on field \"#{field[:field]}\" is deprecated. Please use is_required."
      field[:is_required] = !!field[:isRequired]
      field.delete(:isRequired)
    end

    if field.key?(:isReadOnly)
      FOREST_LOGGER.warn "DEPRECATION WARNING: isReadOnly on field \"#{field[:field]}\" is deprecated. Please use is_read_only."
      field[:is_read_only] = !!field[:isReadOnly]
      field.delete(:isReadOnly)
    end

    field[:type] = "String" unless field.key?(:type)
    field[:default_value] = nil unless field.key?(:default_value)
    field[:enums] = nil unless field.key?(:enums)
    field[:is_required] = false unless field.key?(:is_required)
    field[:is_read_only] = false unless field.key?(:is_read_only)
    field[:reference] = nil unless field.key?(:reference)
    field[:description] = nil unless field.key?(:description)
    field[:widget] = nil unless field.key?(:widget)
    field
  end

  if has_fields_without_name
    FOREST_LOGGER.warn "Please set a name to all your \"#{@name}\" Smart Action fields " \
      "(Smart Actions fields without name are ignored)."
  end

  dasherized_name = ActiveSupport::Inflector.parameterize(@name) unless @name.nil?
  @endpoint ||= "forest/actions/#{dasherized_name}" unless dasherized_name.nil?
  @http_method ||= "POST"
  @redirect ||= nil
  @base_url ||= nil
  @type ||= "bulk"
  @download ||= false
  @hooks = !@hooks.nil? ? @hooks.symbolize_keys : nil
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#downloadObject

Returns the value of attribute download.



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

def download
  @download
end

#endpointObject

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#fieldsObject

Returns the value of attribute fields.



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

def fields
  @fields
end

#hooksObject

Returns the value of attribute hooks.



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

def hooks
  @hooks
end

#http_methodObject

Returns the value of attribute http_method.



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

def http_method
  @http_method
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#redirectObject

Returns the value of attribute redirect.



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

def redirect
  @redirect
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#persisted?Boolean



79
80
81
# File 'app/models/forest_liana/model/action.rb', line 79

def persisted?
  false
end