Class: GoodData::StyleSetting

Inherits:
Rest::Resource show all
Defined in:
lib/gooddata/models/style_setting.rb

Constant Summary collapse

STYLE_SETTING_PATH =
'/gdc/projects/%s/styleSettings'
EMPTY_OBJECT =
{
  'styleSettings' => {
    'chartPalette' => []
  }
}

Instance Attribute Summary collapse

Attributes inherited from Rest::Object

#client, #json, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ObjId

#obj_id

Methods inherited from Rest::Object

client, default_client, #saved?

Methods included from Mixin::DataPropertyReader

#data_property_reader

Methods included from Mixin::DataPropertyWriter

#data_property_writer

Methods included from Mixin::MetaPropertyReader

#metadata_property_reader

Methods included from Mixin::MetaPropertyWriter

#metadata_property_writer

Methods included from Mixin::MetaGetter

#meta

Methods included from Mixin::DataGetter

#data

Methods included from Mixin::RootKeyGetter

#root_key

Methods included from Mixin::ContentGetter

#content

Constructor Details

#initialize(json) ⇒ StyleSetting

Returns a new instance of StyleSetting.



52
53
54
55
56
# File 'lib/gooddata/models/style_setting.rb', line 52

def initialize(json)
  super
  @json = json
  @colors = json ? data['chartPalette'] : []
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



19
20
21
# File 'lib/gooddata/models/style_setting.rb', line 19

def colors
  @colors
end

Class Method Details

.create(colors, opts = { client: GoodData.connection, project: GoodData.project }) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gooddata/models/style_setting.rb', line 29

def create(colors, opts = { client: GoodData.connection, project: GoodData.project })
  client, project = GoodData.get_client_and_project(opts)
  if colors.is_a?(StyleSetting)
    colors = colors.colors
  else
    colors = colors.uniq
  end
  uri = STYLE_SETTING_PATH % project.pid
  data_to_send = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d|
    d['styleSettings']['chartPalette'] = colors.map { |color| GoodData::Helpers.stringify_keys(color) }
  end
  style = client.create(StyleSetting, data_to_send)
  client.put(uri, data_to_send)
  style
end

.current(opts = { client: GoodData.connection, project: GoodData.project }) ⇒ Object



22
23
24
25
26
27
# File 'lib/gooddata/models/style_setting.rb', line 22

def current(opts = { client: GoodData.connection, project: GoodData.project })
  client, project = GoodData.get_client_and_project(opts)
  uri = STYLE_SETTING_PATH % project.pid
  data = client.get(uri)
  client.create(StyleSetting, data)
end

.reset(opts = { client: GoodData.connection, project: GoodData.project }) ⇒ Object



45
46
47
48
49
# File 'lib/gooddata/models/style_setting.rb', line 45

def reset(opts = { client: GoodData.connection, project: GoodData.project })
  client, project = GoodData.get_client_and_project(opts)
  uri = STYLE_SETTING_PATH % project.pid
  client.delete(uri)
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/gooddata/models/style_setting.rb', line 58

def empty?
  colors.empty?
end