Class: Mingle::PropertyDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/mingle_macro_models/property_definition.rb

Overview

This is a lightweight representation of a ProjectDefinition in Mingle

Constant Summary collapse

MANAGED_TEXT_TYPE =
"Managed text list"
ANY_TEXT_TYPE =
"Any text"
MANAGED_NUMBER_TYPE =
"Managed number list"
ANY_NUMBER_TYPE =
"Any number"
DATE_TYPE =
"Date"
FORMULA_TYPE =
"Formula"
USER_TYPE =
"Automatically generated from the team list"
CARD_TYPE =
"Card"
AGGREGATE_TYPE =
"Aggregate"
TREE_RELATIONSHIP_TYPE =
"Any card used in tree"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_property_definition) ⇒ PropertyDefinition

Returns a new instance of PropertyDefinition.



18
19
20
# File 'lib/mingle_macro_models/property_definition.rb', line 18

def initialize(full_property_definition)
  @full_property_definition = full_property_definition
end

Instance Attribute Details

#card_types_property_definitions_loader=(value) ⇒ Object (writeonly)

Sets the attribute card_types_property_definitions_loader

Parameters:

  • value

    the value to set the attribute card_types_property_definitions_loader to.



102
103
104
# File 'lib/mingle_macro_models/property_definition.rb', line 102

def card_types_property_definitions_loader=(value)
  @card_types_property_definitions_loader = value
end

#values_loader=(value) ⇒ Object (writeonly)

Sets the attribute values_loader

Parameters:

  • value

    the value to set the attribute values_loader to.



102
103
104
# File 'lib/mingle_macro_models/property_definition.rb', line 102

def values_loader=(value)
  @values_loader = value
end

Instance Method Details

#calculated?Boolean

returns: True if a property definition has only calculated values, such as ones of Formula & Aggregate types

Returns:

  • (Boolean)


89
90
91
# File 'lib/mingle_macro_models/property_definition.rb', line 89

def calculated?
  type_description == FORMULA_TYPE || type_description == AGGREGATE_TYPE
end

#card_typesObject

returns: A list of CardTypes that this PropertyDefinition is valid for



33
34
35
# File 'lib/mingle_macro_models/property_definition.rb', line 33

def card_types
  @card_types_property_definitions_loader.load.collect(&:card_type).sort_by(&:position)
end

#date?Boolean

returns: True if a property definition has only numeric values, such as the Date type

Returns:

  • (Boolean)


94
95
96
# File 'lib/mingle_macro_models/property_definition.rb', line 94

def date?
  type_description == DATE_TYPE
end

#descriptionObject

returns: The description of this PropertyDefinition



28
29
30
# File 'lib/mingle_macro_models/property_definition.rb', line 28

def description
  @full_property_definition.description
end

#nameObject

returns: The name of this PropertyDefinition



23
24
25
# File 'lib/mingle_macro_models/property_definition.rb', line 23

def name
  @full_property_definition.name
end

#numeric?Boolean

returns: True if a property definition has only numeric values, such as ones of Un/managed number types

Returns:

  • (Boolean)


84
85
86
# File 'lib/mingle_macro_models/property_definition.rb', line 84

def numeric?
  type_description == MANAGED_NUMBER_TYPE || type_description == ANY_NUMBER_TYPE
end

#textual?Boolean

returns: True if a property definition has only textual values, such as ones of Un/managed text types

Returns:

  • (Boolean)


79
80
81
# File 'lib/mingle_macro_models/property_definition.rb', line 79

def textual?
  type_description == MANAGED_TEXT_TYPE || type_description == ANY_TEXT_TYPE
end

#to_sObject



98
99
100
# File 'lib/mingle_macro_models/property_definition.rb', line 98

def to_s
  "PropertyDefinition[name=#{name},type=#{type}]"
end

#type_descriptionObject

returns: A short description of the property definition. This will be one of the above values

  • MANAGED_TEXT_TYPE

  • ANY_TEXT_TYPE

  • MANAGED_NUMBER_TYPE

  • ANY_NUMBER_TYPE

  • DATE_TYPE

  • FORMULA_TYPE

  • USER_TYPE

  • CARD_TYPE

  • AGGREGATE_TYPE

  • TREE_RELATIONSHIP_TYPE



49
50
51
# File 'lib/mingle_macro_models/property_definition.rb', line 49

def type_description
  @full_property_definition.type_description
end

#valuesObject

returns: A list of explicitly defined values that this PropertyDefinition has This method should ONLY be called for property definitions that are of the following types

  • MANAGED_TEXT_TYPE

  • MANAGED_NUMBER_TYPE

  • USER_TYPE

Attempting to call this method for the following types will throw an Exception

  • ANY_TEXT_TYPE

  • ANY_NUMBER_TYPE

  • FORMULA_TYPE

  • AGGREGATE_TYPE

  • CARD_TYPE

  • TREE_RELATIONSHIP_TYPE

  • DATE_TYPE

To get the values for the above types, you can use MQL, such as “SELECT property_name” to get a list of values



70
71
72
73
74
75
76
# File 'lib/mingle_macro_models/property_definition.rb', line 70

def values
  valid_property_types_to_call_value_on = [MANAGED_TEXT_TYPE, MANAGED_NUMBER_TYPE, USER_TYPE]
  unless valid_property_types_to_call_value_on.any? {|t| self.type_description == t}
    raise "Do not call this method for property definitions of types other than MANAGED_TEXT_TYPE, MANAGED_NUMBER_TYPE, USER_TYPE." 
  end  
  @values_loader.load
end