Class: GoodData::Model::SchemaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/models/blueprint/schema_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, options = {}) ⇒ SchemaBuilder

Returns a new instance of SchemaBuilder.



26
27
28
29
30
31
32
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 26

def initialize(id = nil, options = {})
  @data = {
    id: id,
    type: :dataset,
    columns: []
  }.merge(options)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 10

def data
  @data
end

Class Method Details

.create(id, options = {}, &block) ⇒ Object



19
20
21
22
23
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 19

def create(id, options = {}, &block)
  pb = SchemaBuilder.new(id, options)
  block.call(pb)
  pb
end

.create_from_data(blueprint) ⇒ Object



13
14
15
16
17
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 13

def create_from_data(blueprint)
  sc = SchemaBuilder.new
  sc.data = blueprint.to_hash
  sc
end

Instance Method Details

#add_anchor(id, options = {}) ⇒ Object



47
48
49
50
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 47

def add_anchor(id, options = {})
  add_column({ type: :anchor, id: id }.merge(options))
  self
end

#add_attribute(id, options = {}) ⇒ Object



52
53
54
55
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 52

def add_attribute(id, options = {})
  add_column({ type: :attribute, id: id }.merge(options))
  self
end

#add_column(column_def) ⇒ Object



42
43
44
45
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 42

def add_column(column_def)
  columns.push(column_def)
  self
end

#add_date(dataset_id, options = {}) ⇒ Object



68
69
70
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 68

def add_date(dataset_id, options = {})
  add_column({ type: :date, dataset: dataset_id, format: GoodData::Model::DEFAULT_DATE_FORMAT }.merge(options))
end

#add_fact(id, options = {}) ⇒ Object



57
58
59
60
61
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 57

def add_fact(id, options = {})
  data = { type: :fact, id: id }.merge(options)
  add_column(data)
  self
end

#add_label(id, options = {}) ⇒ Object



63
64
65
66
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 63

def add_label(id, options = {})
  add_column({ type: :label, id: id }.merge(options))
  self
end

#add_reference(dataset, options = {}) ⇒ Object



72
73
74
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 72

def add_reference(dataset, options = {})
  add_column({ type: :reference, dataset: dataset }.merge(options))
end

#columnsObject



38
39
40
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 38

def columns
  data[:columns]
end

#nameObject



34
35
36
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 34

def name
  data[:name]
end

#to_blueprintObject



84
85
86
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 84

def to_blueprint
  GoodData::Model::ProjectBlueprint.new(datasets: [to_hash])
end

#to_hashObject



80
81
82
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 80

def to_hash
  data
end

#to_jsonObject



76
77
78
# File 'lib/gooddata/models/blueprint/schema_builder.rb', line 76

def to_json
  JSON.pretty_generate(to_hash)
end