Class: SfCli::Sf::Model::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/sf_cli/sf/model/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Schema

Returns a new instance of Schema.



7
8
9
# File 'lib/sf_cli/sf/model/schema.rb', line 7

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/sf_cli/sf/model/schema.rb', line 5

def schema
  @schema
end

Instance Method Details

#children_relationsObject



19
20
21
22
23
# File 'lib/sf_cli/sf/model/schema.rb', line 19

def children_relations
  schema['childRelationships']
    .select{|r| r['relationshipName'].nil? == false}
    .map{|r| {name: r['relationshipName'].to_sym, class_name: r['childSObject'].to_sym}}
end

#field_namesObject



15
16
17
# File 'lib/sf_cli/sf/model/schema.rb', line 15

def field_names
  schema['fields'].map{|f| f['name'].to_sym}
end

#nameObject



11
12
13
# File 'lib/sf_cli/sf/model/schema.rb', line 11

def name
  schema['name']
end

#parent_relationsObject



25
26
27
28
29
# File 'lib/sf_cli/sf/model/schema.rb', line 25

def parent_relations
  schema['fields']
    .select{|f| f['relationshipName'].nil? == false && f['referenceTo']&.size > 0}
    .map{|f| {name: f['relationshipName'].to_sym, class_name: f['referenceTo'].first.to_sym}}
end