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.



498
499
500
# File 'lib/etna/clients/magma/models.rb', line 498

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

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

Class Method Details

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



657
658
659
660
661
662
663
# File 'lib/etna/clients/magma/models.rb', line 657

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



621
622
623
# File 'lib/etna/clients/magma/models.rb', line 621

def attribute_group
  raw['attribute_group']
end

#attribute_group=(val) ⇒ Object



625
626
627
# File 'lib/etna/clients/magma/models.rb', line 625

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

#attribute_nameObject



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

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

#attribute_name=(val) ⇒ Object



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

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

#attribute_typeObject



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

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

#attribute_type=(val) ⇒ Object



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

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

#descriptionObject



577
578
579
# File 'lib/etna/clients/magma/models.rb', line 577

def description
  raw['description']
end

#description=(val) ⇒ Object



581
582
583
# File 'lib/etna/clients/magma/models.rb', line 581

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

#display_nameObject



585
586
587
# File 'lib/etna/clients/magma/models.rb', line 585

def display_name
  raw['display_name']
end

#display_name=(val) ⇒ Object



589
590
591
# File 'lib/etna/clients/magma/models.rb', line 589

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

#format_hintObject



605
606
607
# File 'lib/etna/clients/magma/models.rb', line 605

def format_hint
  raw['format_hint']
end

#format_hint=(val) ⇒ Object



609
610
611
# File 'lib/etna/clients/magma/models.rb', line 609

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

#hiddenObject



629
630
631
# File 'lib/etna/clients/magma/models.rb', line 629

def hidden
  raw['hidden']
end

#hidden=(val) ⇒ Object



633
634
635
# File 'lib/etna/clients/magma/models.rb', line 633

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

#is_edited?(other) ⇒ Boolean

Returns:

  • (Boolean)


502
503
504
505
506
507
508
509
510
# File 'lib/etna/clients/magma/models.rb', line 502

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)


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

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


553
554
555
# File 'lib/etna/clients/magma/models.rb', line 553

def link_attribute_name
  @raw['link_attribute_name']
end


557
558
559
# File 'lib/etna/clients/magma/models.rb', line 557

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


561
562
563
# File 'lib/etna/clients/magma/models.rb', line 561

def link_model_name
  @raw['link_model_name']
end


565
566
567
# File 'lib/etna/clients/magma/models.rb', line 565

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

#matchObject



593
594
595
# File 'lib/etna/clients/magma/models.rb', line 593

def match
  raw['match']
end

#nameObject



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

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

#name=(val) ⇒ Object



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

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

#optionsObject



645
646
647
# File 'lib/etna/clients/magma/models.rb', line 645

def options
  raw['options']
end

#read_onlyObject



613
614
615
# File 'lib/etna/clients/magma/models.rb', line 613

def read_only
  raw['read_only']
end

#read_only=(val) ⇒ Object



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

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

#restrictedObject



597
598
599
# File 'lib/etna/clients/magma/models.rb', line 597

def restricted
  raw['restricted']
end

#restricted=(val) ⇒ Object



601
602
603
# File 'lib/etna/clients/magma/models.rb', line 601

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.



513
514
515
516
517
518
519
520
# File 'lib/etna/clients/magma/models.rb', line 513

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

#uniqueObject



569
570
571
# File 'lib/etna/clients/magma/models.rb', line 569

def unique
  raw['unique']
end

#unique=(val) ⇒ Object



573
574
575
# File 'lib/etna/clients/magma/models.rb', line 573

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

#validationObject



637
638
639
# File 'lib/etna/clients/magma/models.rb', line 637

def validation
  raw['validation']
end

#validation=(val) ⇒ Object



641
642
643
# File 'lib/etna/clients/magma/models.rb', line 641

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