Class: Etna::Clients::Magma::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/etna/clients/magma/models.rb

Constant Summary collapse

COPYABLE_ATTRIBUTE_ATTRIBUTES =
[
    :attribute_name, :attribute_type, :display_name, :format_hint,
    :hidden, :link_model_name, :read_only, :attribute_group, :unique, :validation,
    :restricted, :description
]
EDITABLE_ATTRIBUTE_ATTRIBUTES =
UpdateAttributeAction.members & COPYABLE_ATTRIBUTE_ATTRIBUTES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw = {}) ⇒ Attribute

Returns a new instance of Attribute.



456
457
458
# File 'lib/etna/clients/magma/models.rb', line 456

def initialize(raw = {})
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



454
455
456
# File 'lib/etna/clients/magma/models.rb', line 454

def raw
  @raw
end

Class Method Details

.copy(source, dest, attributes: COPYABLE_ATTRIBUTE_ATTRIBUTES) ⇒ Object



615
616
617
618
619
620
621
# File 'lib/etna/clients/magma/models.rb', line 615

def self.copy(source, dest, attributes: COPYABLE_ATTRIBUTE_ATTRIBUTES)
  attributes.each do |attr_name|
    next unless dest.respond_to?(:"#{attr_name}=")
    source_v = source.send(attr_name)
    dest.send(:"#{attr_name}=", source_v)
  end
end

Instance Method Details

#attribute_groupObject



579
580
581
# File 'lib/etna/clients/magma/models.rb', line 579

def attribute_group
  raw['attribute_group']
end

#attribute_group=(val) ⇒ Object



583
584
585
# File 'lib/etna/clients/magma/models.rb', line 583

def attribute_group=(val)
  raw['attribute_group'] = val
end

#attribute_nameObject



488
489
490
# File 'lib/etna/clients/magma/models.rb', line 488

def attribute_name
  @raw['attribute_name'] || ""
end

#attribute_name=(val) ⇒ Object



492
493
494
# File 'lib/etna/clients/magma/models.rb', line 492

def attribute_name=(val)
  @raw['attribute_name'] = val
end

#attribute_typeObject



496
497
498
# File 'lib/etna/clients/magma/models.rb', line 496

def attribute_type
  @raw['attribute_type'] && AttributeType.new(@raw['attribute_type'])
end

#attribute_type=(val) ⇒ Object



506
507
508
509
# File 'lib/etna/clients/magma/models.rb', line 506

def attribute_type=(val)
  val = val.to_s if val
  @raw['attribute_type'] = val
end

#descriptionObject



535
536
537
# File 'lib/etna/clients/magma/models.rb', line 535

def description
  raw['description']
end

#description=(val) ⇒ Object



539
540
541
# File 'lib/etna/clients/magma/models.rb', line 539

def description=(val)
  @raw['description'] = val
end

#display_nameObject



543
544
545
# File 'lib/etna/clients/magma/models.rb', line 543

def display_name
  raw['display_name']
end

#display_name=(val) ⇒ Object



547
548
549
# File 'lib/etna/clients/magma/models.rb', line 547

def display_name=(val)
  raw['display_name'] = val
end

#format_hintObject



563
564
565
# File 'lib/etna/clients/magma/models.rb', line 563

def format_hint
  raw['format_hint']
end

#format_hint=(val) ⇒ Object



567
568
569
# File 'lib/etna/clients/magma/models.rb', line 567

def format_hint=(val)
  raw['format_hint'] = val
end

#hiddenObject



587
588
589
# File 'lib/etna/clients/magma/models.rb', line 587

def hidden
  raw['hidden']
end

#hidden=(val) ⇒ Object



591
592
593
# File 'lib/etna/clients/magma/models.rb', line 591

def hidden=(val)
  raw['hidden'] = val
end

#is_edited?(other) ⇒ Boolean

Returns:

  • (Boolean)


460
461
462
463
464
465
466
467
468
# File 'lib/etna/clients/magma/models.rb', line 460

def is_edited?(other)
  # Don't just override == in case need to do a full comparison.
  editable_attribute_names = Attribute::EDITABLE_ATTRIBUTE_ATTRIBUTES.map(&:to_s)

  self_editable = raw.slice(*editable_attribute_names)
  other_editable = other.raw.slice(*editable_attribute_names)

  self_editable != other_editable
end

#is_project_name_reference?(model_name) ⇒ Boolean

Returns:

  • (Boolean)


500
501
502
503
504
# File 'lib/etna/clients/magma/models.rb', line 500

def is_project_name_reference?(model_name)
  return true if model_name == 'project' && attribute_type == AttributeType::IDENTIFIER
  return true if link_model_name == 'project'
  false
end


511
512
513
# File 'lib/etna/clients/magma/models.rb', line 511

def link_attribute_name
  @raw['link_attribute_name']
end


515
516
517
# File 'lib/etna/clients/magma/models.rb', line 515

def link_attribute_name=(val)
  @raw['link_attribute_name'] = val
end


519
520
521
# File 'lib/etna/clients/magma/models.rb', line 519

def link_model_name
  @raw['link_model_name']
end


523
524
525
# File 'lib/etna/clients/magma/models.rb', line 523

def link_model_name=(val)
  @raw['link_model_name'] = val
end

#matchObject



551
552
553
# File 'lib/etna/clients/magma/models.rb', line 551

def match
  raw['match']
end

#nameObject



480
481
482
# File 'lib/etna/clients/magma/models.rb', line 480

def name
  @raw['name'] || ""
end

#name=(val) ⇒ Object



484
485
486
# File 'lib/etna/clients/magma/models.rb', line 484

def name=(val)
  @raw['name'] = val
end

#optionsObject



603
604
605
# File 'lib/etna/clients/magma/models.rb', line 603

def options
  raw['options']
end

#read_onlyObject



571
572
573
# File 'lib/etna/clients/magma/models.rb', line 571

def read_only
  raw['read_only']
end

#read_only=(val) ⇒ Object



575
576
577
# File 'lib/etna/clients/magma/models.rb', line 575

def read_only=(val)
  raw['read_only'] = val
end

#restrictedObject



555
556
557
# File 'lib/etna/clients/magma/models.rb', line 555

def restricted
  raw['restricted']
end

#restricted=(val) ⇒ Object



559
560
561
# File 'lib/etna/clients/magma/models.rb', line 559

def restricted=(val)
  raw['restricted'] = val
end

#set_field_defaults!Object

Sets certain attribute fields which are implicit, even when not set, to match server behavior.



471
472
473
474
475
476
477
478
# File 'lib/etna/clients/magma/models.rb', line 471

def set_field_defaults!
  @raw.replace({
      'hidden' => false,
      'read_only' => false,
      'restricted' => false,
      'validation' => nil,
  }.merge(@raw))
end

#uniqueObject



527
528
529
# File 'lib/etna/clients/magma/models.rb', line 527

def unique
  raw['unique']
end

#unique=(val) ⇒ Object



531
532
533
# File 'lib/etna/clients/magma/models.rb', line 531

def unique=(val)
  raw['unique'] = val
end

#validationObject



595
596
597
# File 'lib/etna/clients/magma/models.rb', line 595

def validation
  raw['validation']
end

#validation=(val) ⇒ Object



599
600
601
# File 'lib/etna/clients/magma/models.rb', line 599

def validation=(val)
  raw['validation'] = val
end