Class: Ecoportal::API::Internal::Account

Inherits:
Common::BaseModel show all
Defined in:
lib/ecoportal/api/internal/account.rb

Constant Summary collapse

VALID_TAG_REGEX =
/^[A-Za-z0-9 &_'\/-]+$/

Instance Attribute Summary

Attributes inherited from Common::BaseModel

#_key, #_parent

Instance Method Summary collapse

Methods inherited from Common::BaseModel

#as_update, #consolidate!, #dirty?, #doc, embeds_one, #initialize, #original_doc, passthrough, #print, #reset!, #to_json

Methods included from Common::BaseClass

#class_resolver, #resolve_class

Constructor Details

This class inherits a constructor from Ecoportal::API::Common::BaseModel

Instance Method Details

#as_jsonObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/ecoportal/api/internal/account.rb', line 47

def as_json
  super.tap do |hash|
    if preset == "custom"
      hash["permissions_custom"] = permissions.as_json
    else
      hash.delete "permissions_custom"
    end
    hash["preferences"] = preferences.as_json
  end
end

#filter_tags=(value) ⇒ Object

Note:

all is set in upper case.

Validates the string tags of the array, and sets the filter_tags property of the account.

Parameters:

  • value (Array<String>)

    array of tags.

Raises:

  • (Exception)

    if there was any invalid string tag.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ecoportal/api/internal/account.rb', line 35

def filter_tags=(value)
  unless value.is_a?(Array)
    raise "filter_tags= needs to be passed an Array, got #{value.class}"
  end
  doc["filter_tags"] = value.map do |tag|
    unless tag.match(VALID_TAG_REGEX)
      raise "Invalid filter tag #{tag.inspect}"
    end
    tag.upcase
  end
end

#presetnil, String

Note:

basically the same as permissions_preset but when 'nil', it returns "custom" instead

Gets the permissions_preset.

Returns:

  • (nil, String)

    preset name.



27
28
29
# File 'lib/ecoportal/api/internal/account.rb', line 27

def preset
  self.permissions_preset.nil? ? "custom" : self.permissions_preset
end

#preset=(value) ⇒ Object

Note:

basically the same as permissions_preset= but when "custom", it's changed to nil

Sets the permissions_preset.

Parameters:

  • value (nil, String)

    preset name.



20
21
22
# File 'lib/ecoportal/api/internal/account.rb', line 20

def preset=(value)
  self.permissions_preset = value == "custom" ? nil : value
end