File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # encoding: UTF-8
2+
3+ module GoodData
4+ # Project Not Found
5+ class AttributeElementNotFound < RuntimeError
6+ DEFAULT_MSG = 'Attribute element "%s" was not found'
7+
8+ def initialize ( value , msg = DEFAULT_MSG )
9+ super ( sprintf ( DEFAULT_MSG , value ) )
10+ end
11+ end
12+ end
Original file line number Diff line number Diff line change @@ -14,11 +14,11 @@ class Label < GoodData::MdObject
1414 # @param [String] value value of an label you are looking for
1515 # @return [String]
1616 def find_value_uri ( value )
17- value = CGI . escape ( value )
18- results = GoodData . post ( "#{ uri } /validElements?limit=30&offset=0&order=asc&filter=#{ value } " , { } )
17+ escaped_value = CGI . escape ( value )
18+ results = GoodData . post ( "#{ uri } /validElements?limit=30&offset=0&order=asc&filter=#{ escaped_value } " , { } )
1919 items = results [ 'validElements' ] [ 'items' ]
2020 if items . empty?
21- fail " #{ value } not found"
21+ fail ( AttributeElementNotFound , value )
2222 else
2323 items . first [ 'element' ] [ 'uri' ]
2424 end
@@ -39,6 +39,16 @@ def find_element_value(element_id)
3939 end
4040 end
4141
42+ # Finds if a label has an attribute element for given value.
43+ # @param [String] value value of an label you are looking for
44+ # @return [Boolean]
45+ def value? ( value )
46+ find_value_uri ( value )
47+ true
48+ rescue AttributeElementNotFound
49+ false
50+ end
51+
4252 # Returns all values for this label. This is for inspection purposes only since obviously there can be huge number of elements.
4353 # @param [Hash] options the options to pass to the value list
4454 # @option options [Number] :limit limits the number of values to certain number. Default is 100
Original file line number Diff line number Diff line change 282282 l = attribute . primary_label
283283 value = l . values . first [ :value ]
284284 l . find_element_value ( l . find_value_uri ( value ) ) . should == value
285+ expect ( l . value? ( value ) ) . should == true
286+ expect ( l . value? ( "DEFINITELY NON EXISTENT VALUE HOPEFULLY" ) ) . should == false
285287 end
286288 end
287289
You can’t perform that action at this time.
0 commit comments