Class: Ecoportal::API::Internal::Account
- Inherits:
-
Common::BaseModel
- Object
- Common::BaseModel
- Ecoportal::API::Internal::Account
- 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
Instance Method Summary collapse
- #as_json ⇒ Object
-
#filter_tags=(value) ⇒ Object
Validates the string tags of the array, and sets the
filter_tagsproperty of the account. -
#preset ⇒ nil, String
Gets the
permissions_preset. -
#preset=(value) ⇒ Object
Sets the
permissions_preset.
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_json ⇒ Object
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"] = .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.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ecoportal/api/internal/account.rb', line 35 def (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 |
#preset ⇒ nil, String
Note:
basically the same as permissions_preset but when 'nil', it returns "custom" instead
Gets the permissions_preset.
27 28 29 |
# File 'lib/ecoportal/api/internal/account.rb', line 27 def preset self..nil? ? "custom" : self. end |
#preset=(value) ⇒ Object
Note:
basically the same as permissions_preset= but when "custom", it's changed to nil
Sets the permissions_preset.
20 21 22 |
# File 'lib/ecoportal/api/internal/account.rb', line 20 def preset=(value) self. = value == "custom" ? nil : value end |