mingle_macro_models 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ #Copyright 2012 ThoughtWorks, Inc. All rights reserved.
2
+
3
+ Dir.glob(File.join(File.dirname(__FILE__), "mingle_macro_models", "*.rb")).each do |file|
4
+ require file
5
+ end
@@ -0,0 +1,41 @@
1
+ module Mingle
2
+ # Copyright 2009 ThoughtWorks, Inc. All rights reserved.
3
+
4
+ # This is a lightweight representation of a card type in Mingle.
5
+ # From an instance of this class you can the name, color and position of the card type,
6
+ # in addition to Property Definitions that are associated with it.
7
+ class CardType
8
+
9
+ def initialize(full_card_type)
10
+ @full_card_type = full_card_type
11
+ end
12
+
13
+ # *returns*: The name of this CardType
14
+ def name
15
+ @full_card_type.name
16
+ end
17
+
18
+ # *returns*: The hex color code for this CardType
19
+ def color
20
+ @full_card_type.color.gsub('#', '')
21
+ end
22
+
23
+ # *returns*: The position of this CardType among all the CardTypes on the project.
24
+ # The first card type has position 1
25
+ def position
26
+ @full_card_type.position
27
+ end
28
+
29
+ # *returns*: The PropertyDefinitions associated with this CardType
30
+ def property_definitions
31
+ @card_types_property_definitions_loader.load.collect(&:property_definition)
32
+ end
33
+
34
+ def to_s
35
+ "CardType[name=#{name},color=#{color},position=#{position}]"
36
+ end
37
+
38
+ attr_writer :card_types_property_definitions_loader
39
+ end
40
+
41
+ end
@@ -0,0 +1,26 @@
1
+ module Mingle
2
+ # Copyright 2010 ThoughtWorks, Inc. All rights reserved.
3
+
4
+ # This is a lightweight representation of the relationship between a card_type
5
+ # and a property definition as configured in Mingle.
6
+ class CardTypePropertyDefinition
7
+ def initialize(card_type_property_definition)
8
+ @card_type_property_definition = card_type_property_definition
9
+ end
10
+
11
+ def position
12
+ @card_type_property_definition.position.to_i
13
+ end
14
+
15
+ def card_type
16
+ @card_type_loader.load
17
+ end
18
+
19
+ def property_definition
20
+ @property_definition_loader.load
21
+ end
22
+
23
+ attr_writer :card_type_loader, :property_definition_loader
24
+ end
25
+
26
+ end
@@ -0,0 +1,168 @@
1
+ module Mingle
2
+ # Copyright 2010 ThoughtWorks, Inc. All rights reserved.
3
+
4
+ # This is a lightweight representation of a project.
5
+ # From an instance of this class you can the name & identifier of the project.
6
+ # You can also get a list of property definitions and card types on the project,
7
+ # in addition to information about the team and project variables.
8
+ # This class also provides an interface to the MQL execution facilities provided by Mingle.
9
+ class Project
10
+
11
+ VERSION_ONE = 'v1'
12
+ VERSION_TWO = 'v2'
13
+
14
+ def initialize(project, card_query_options)
15
+ @full_project = project
16
+ @card_query_options = card_query_options
17
+ end
18
+
19
+ # *returns*: The identifier of this project
20
+ def identifier
21
+ @full_project.identifier
22
+ end
23
+
24
+ # *returns*: The name of this project
25
+ def name
26
+ @full_project.name
27
+ end
28
+
29
+ # *returns*: A list CardTypes as configured for this project.
30
+ # There will always be at least one element in this list.
31
+ def card_types
32
+ @card_types_loader.load.collect(&:card_type)
33
+ end
34
+
35
+ # *returns*: An list of PropertyDefinitions as configured for this project, which may be empty
36
+ def property_definitions
37
+ @property_definitions_loader.load.collect(&:property_definition)
38
+ end
39
+
40
+ # *accepts*: The name of a project variable configured for this project
41
+ #
42
+ # *returns*: The display value of the PropertyValue(s) that project_variable_name represents
43
+ def value_of_project_variable(project_variable_name)
44
+ @project_variables_loader.load.detect { |pv| pv.name == project_variable_name }.value
45
+ end
46
+
47
+ # *accepts*: A valid MQL string. To see what constitutes valid MQL,
48
+ # look here[http://studios.thoughtworks.com/mingle-agile-project-management/3.0/help/index.html]
49
+ #
50
+ # *returns*: An Array of Hashes, in which each Hash represents one row of results from the MQL execution
51
+ # The keys in the Hash are the names of the properties selected, with all the alphanumeric characters
52
+ # downcased and all the spaces and special characters replaced with underscores(_).
53
+ #
54
+ # Executing a mql statement with explictly supplied property names will return results as follows
55
+ # mql = select number,"defect status" where type=defect
56
+ #
57
+ # [
58
+ # {"number"=>"106", "defect_status"=>"Fixed"},
59
+ # {"number"=>"70", "defect_status"=>"Fixed"},
60
+ # {"number"=>"69", "defect_status"=>"New"},
61
+ # {"number"=>"68", "defect_status"=>"In Progress"},
62
+ # ...
63
+ # ...
64
+ # ]
65
+ #
66
+ # If aggregate functions are selected, the values look as below
67
+ # mql = select "defect status", count(*) where type=defect group by "defect status"
68
+ #
69
+ # [
70
+ # {"count"=>"14", "defect_status"=>"New"},
71
+ # {"count"=>"3", "defect_status"=>"Open"},
72
+ # {"count"=>"1", "defect_status"=>"In Progress"},
73
+ # {"count"=>"2", "defect_status"=>"Fixed"},
74
+ # {"count"=>"1", "defect_status"=>"Closed"}
75
+ # ]
76
+ #
77
+ # If no columns are explicitly provided, the results contain the raw column names specific
78
+ # properties. It is not possible to interpret these results in the general case with the current
79
+ # version of the macro development toolkit, so this is not a particularly useful form of
80
+ # MQL to execute. The documentation here is provided here just for completeness and should
81
+ # not be used as a recommended way of using this call. The structure of this response is
82
+ # subject to change in future versions of the toolkit.
83
+ #
84
+ # mql = type=defect
85
+ #
86
+ # {
87
+ # "cp_testing_status"=>"Ready to Be Tested",
88
+ # "cp_actual_effort"=>nil,
89
+ # "created_at"=>"2009-09-09 21:45:34",
90
+ # "cp_story_count"=>nil,
91
+ # "caching_stamp"=>"2",
92
+ # "cp_release_card_id"=>"2",
93
+ # "cp_risk_liklihood"=>nil,
94
+ # "cp_build_completed"=>"452",
95
+ # "cp_closed"=>nil,
96
+ # "has_macros"=>"f",
97
+ # "description"=>"",
98
+ # "cp_release_start_date"=>nil,
99
+ # "cp_risk_status"=>nil,
100
+ # "cp_story_time_to_life"=>nil,
101
+ # "cp_total_open_iterations"=>nil,
102
+ # "cp_defect_time_to_life"=>"50.00",
103
+ # "cp_development_started_on"=>nil,
104
+ # "card_type_name"=>"Defect",
105
+ # "cp_added_to_scope_on"=>nil,
106
+ # "cp_owner_user_id"=>nil,
107
+ # "cp_added_to_scope_card_id"=>nil,
108
+ # "cp_type_of_test"=>nil,
109
+ # "cp_velocity"=>nil,
110
+ # "cp_feature_card_id"=>"60"
111
+ # }
112
+ #
113
+ # Note: In versions of the toolkit beyond 1.3, the keys for the aggregate function
114
+ # (such as COUNT, SUM etc.) have been normalized to follow the same conventions as a
115
+ # property name, i.e. lowecase and stripped of all spaces.
116
+ # If you wish to get the results in the old form, set the optional second parameter
117
+ # of this call to be Project::VERSION_ONE, while you transition your macros to use the new form.
118
+ # The old version of response will be deprecated in a future version of Mingle and the toolkit.
119
+ def execute_mql(mql, version = VERSION_TWO)
120
+ @full_project.with_active_project do
121
+ CardQuery.parse(mql, @card_query_options).values_for_macro(:api_version => version)
122
+ end
123
+ end
124
+
125
+ # The macros on a page determine whether the page content is cached. Macros that use certain MQL concepts
126
+ # (for example TODAY, CURRENT USER, or cross-project functionality) should report that they cannot be
127
+ # cached so that the page they are on is not cached. This method indicates whether a MQL query uses
128
+ # those concepts, and can be used by a macro to determine whether or not to report that it should be
129
+ # cached.
130
+ #
131
+ # *accepts*: A valid MQL string. To see what constitutes valid MQL,
132
+ # look here[http://studios.thoughtworks.com/mingle-agile-project-management/3.0/help/index.html]
133
+ #
134
+ # *returns*: A boolean indicating whether the data pertaining to the MQL can be cached
135
+ def can_be_cached?(mql)
136
+ @full_project.with_active_project do
137
+ CardQuery.parse(mql, @card_query_options).can_be_cached?
138
+ end
139
+ end
140
+
141
+ # *returns*: The full list of Users who are members of this project
142
+ def team
143
+ @team_loader.load
144
+ end
145
+
146
+ # *accepts*: Any Number
147
+ #
148
+ # *returns*: The argument number formatted to the precision configured for the project (default 2)
149
+ def format_number_with_project_precision(number)
150
+ @full_project.to_num(number)
151
+ end
152
+
153
+ # *accepts*: Any Number
154
+ #
155
+ # *returns*: The argument date formatted using the date format configured for the project
156
+ def format_date_with_project_date_format(date)
157
+ @full_project.format_date(date)
158
+ end
159
+
160
+ attr_writer :card_types_loader, :property_definitions_loader, :team_loader, :project_variables_loader
161
+
162
+ private
163
+ def add_alert(message)
164
+ @card_query_options[:alert_receiver].alert(message) if @card_query_options[:alert_receiver]
165
+ end
166
+ end
167
+
168
+ end
@@ -0,0 +1,24 @@
1
+ module Mingle
2
+ # Copyright 2009 ThoughtWorks, Inc. All rights reserved.
3
+
4
+ # This is a lightweight representation of a ProjectVariable in Mingle
5
+ # A property defintion is a mnemonic name that represents a particular
6
+ # value for one or more PropertyDefinitions
7
+ class ProjectVariable
8
+
9
+ def initialize(full_project_variable)
10
+ @full_project_variable = full_project_variable
11
+ end
12
+
13
+ # *returns*: The name of this variable
14
+ def name
15
+ @full_project_variable.name
16
+ end
17
+
18
+ # *returns*: The display value of the value configured for this project variable
19
+ def value
20
+ @full_project_variable.display_value
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,105 @@
1
+ module Mingle
2
+ # Copyright 2009 ThoughtWorks, Inc. All rights reserved.
3
+
4
+ # This is a lightweight representation of a ProjectDefinition in Mingle
5
+ class PropertyDefinition
6
+
7
+ MANAGED_TEXT_TYPE = "Managed text list"
8
+ ANY_TEXT_TYPE = "Any text"
9
+ MANAGED_NUMBER_TYPE = "Managed number list"
10
+ ANY_NUMBER_TYPE = "Any number"
11
+ DATE_TYPE = "Date"
12
+ FORMULA_TYPE = "Formula"
13
+ USER_TYPE = "Automatically generated from the team list"
14
+ CARD_TYPE = "Card"
15
+ AGGREGATE_TYPE = "Aggregate"
16
+ TREE_RELATIONSHIP_TYPE = "Any card used in tree"
17
+
18
+ def initialize(full_property_definition)
19
+ @full_property_definition = full_property_definition
20
+ end
21
+
22
+ # *returns*: The name of this PropertyDefinition
23
+ def name
24
+ @full_property_definition.name
25
+ end
26
+
27
+ # *returns*: The description of this PropertyDefinition
28
+ def description
29
+ @full_property_definition.description
30
+ end
31
+
32
+ # *returns*: A list of CardTypes that this PropertyDefinition is valid for
33
+ def card_types
34
+ @card_types_property_definitions_loader.load.collect(&:card_type).sort_by(&:position)
35
+ end
36
+
37
+ # *returns*: A short description of the property definition.
38
+ # This will be one of the above values
39
+ # - MANAGED_TEXT_TYPE
40
+ # - ANY_TEXT_TYPE
41
+ # - MANAGED_NUMBER_TYPE
42
+ # - ANY_NUMBER_TYPE
43
+ # - DATE_TYPE
44
+ # - FORMULA_TYPE
45
+ # - USER_TYPE
46
+ # - CARD_TYPE
47
+ # - AGGREGATE_TYPE
48
+ # - TREE_RELATIONSHIP_TYPE
49
+ def type_description
50
+ @full_property_definition.type_description
51
+ end
52
+
53
+ # *returns*: A list of explicitly defined values that this PropertyDefinition has
54
+ # This method should ONLY be called for property definitions that are of the following types
55
+ # - MANAGED_TEXT_TYPE
56
+ # - MANAGED_NUMBER_TYPE
57
+ # - USER_TYPE
58
+ #
59
+ # Attempting to call this method for the following types will throw an Exception
60
+ # - ANY_TEXT_TYPE
61
+ # - ANY_NUMBER_TYPE
62
+ # - FORMULA_TYPE
63
+ # - AGGREGATE_TYPE
64
+ # - CARD_TYPE
65
+ # - TREE_RELATIONSHIP_TYPE
66
+ # - DATE_TYPE
67
+ #
68
+ # To get the values for the above types, you can use MQL, such as "SELECT property_name" to get
69
+ # a list of values
70
+ def values
71
+ valid_property_types_to_call_value_on = [MANAGED_TEXT_TYPE, MANAGED_NUMBER_TYPE, USER_TYPE]
72
+ unless valid_property_types_to_call_value_on.any? {|t| self.type_description == t}
73
+ raise "Do not call this method for property definitions of types other than MANAGED_TEXT_TYPE, MANAGED_NUMBER_TYPE, USER_TYPE."
74
+ end
75
+ @values_loader.load
76
+ end
77
+
78
+ # *returns*: True if a property definition has only textual values, such as ones of Un/managed text types
79
+ def textual?
80
+ type_description == MANAGED_TEXT_TYPE || type_description == ANY_TEXT_TYPE
81
+ end
82
+
83
+ # *returns*: True if a property definition has only numeric values, such as ones of Un/managed number types
84
+ def numeric?
85
+ type_description == MANAGED_NUMBER_TYPE || type_description == ANY_NUMBER_TYPE
86
+ end
87
+
88
+ # *returns*: True if a property definition has only calculated values, such as ones of Formula & Aggregate types
89
+ def calculated?
90
+ type_description == FORMULA_TYPE || type_description == AGGREGATE_TYPE
91
+ end
92
+
93
+ # *returns*: True if a property definition has only numeric values, such as the Date type
94
+ def date?
95
+ type_description == DATE_TYPE
96
+ end
97
+
98
+ def to_s
99
+ "PropertyDefinition[name=#{name},type=#{type}]"
100
+ end
101
+
102
+ attr_writer :card_types_property_definitions_loader, :values_loader
103
+ end
104
+
105
+ end
@@ -0,0 +1,67 @@
1
+ module Mingle
2
+
3
+ # Copyright 2009 ThoughtWorks, Inc. All rights reserved.
4
+ class PropertyValue
5
+
6
+ def initialize(property_value)
7
+ @property_value = property_value
8
+ end
9
+
10
+ # *returns*: The display value of this value
11
+ # Use the result of this method to display this value on the UI
12
+ # For the various property types, the following are the values you can expect to see
13
+ # * Managed/Unmanaged text : The string value of the value
14
+ # * Managed/Unmanaged numeric : The numeric string representation of the value
15
+ # * Date : The list of values this property has on all cards on the project, formatted using the project date format
16
+ # * User : The name of the user
17
+ # * Formula : Either the date or the numeric value, formatted as above
18
+ # * Card : The number of the card, followed by the name of the card
19
+ def display_value
20
+ @property_value.display_value
21
+ end
22
+
23
+ # *returns*: The identifier that is used to represent this value in the database
24
+ # You will most likely not have to use this value in your macros
25
+ # For the various property types, the following are the values you can expect to see
26
+ # * Managed/Unmanaged text : The string value of the value
27
+ # * Managed/Unmanaged numeric : The numeric string representation of the value
28
+ # * Date : The canonical date format, as stored in the database
29
+ # * User : The id of the user in the database
30
+ # * Formula : Either the date or the numeric value, formatted as above
31
+ # * Card : The id of the card in the database
32
+ def db_identifier
33
+ @property_value.db_identifier
34
+ end
35
+
36
+ # *returns*: A representation of this value that is unique and representable in a URL
37
+ # Use the result of this method if in any links that you want to build to point back into Mingle
38
+ # For the various property types, the following are the values you can expect to see
39
+ # * Managed/Unmanaged text : The string value of the value
40
+ # * Managed/Unmanaged numeric : The numeric string representation of the value
41
+ # * Date : The list of values this property has on all cards on the project, formatted using the project date format
42
+ # * User : The login of the user
43
+ # * Formula : Either the date or the numeric value, formatted as above
44
+ # * Card : The number of the card, followed by the name of the card
45
+ def url_identifier
46
+ @property_value.url_identifier
47
+ end
48
+
49
+ # *returns*: The hex color code for this PropertyValue
50
+ def color
51
+ @property_value.color.gsub('#', '')
52
+ end
53
+
54
+ # *returns*: The PropertyDefinition that this value belongs to
55
+ def property_definition
56
+ @property_definition_loader.load
57
+ end
58
+
59
+ def to_s
60
+ "PropertyValue[display_value=#{display_value},db_identifier=#{db_identifier},url_identifier=#{url_identifier}]"
61
+ end
62
+
63
+ attr_writer :property_definition_loader
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,29 @@
1
+ #Copyright 2012 ThoughtWorks, Inc. All rights reserved.
2
+ # A lightweight model of a user in Mingle.
3
+ module Mingle
4
+ class User
5
+ def initialize(full_user)
6
+ @full_user = full_user
7
+ end
8
+
9
+ # *returns*: The login of the user as configured in Mingle
10
+ def login
11
+ @full_user.login
12
+ end
13
+
14
+ # *returns*: The full name of the user as configured in Mingle
15
+ def name
16
+ @full_user.name
17
+ end
18
+
19
+ # *returns*: The version control user name of the user as configured in Mingle
20
+ def version_control_user_name
21
+ @full_user.version_control_user_name
22
+ end
23
+
24
+ # *returns*: The email address of the user as configured in Mingle
25
+ def email
26
+ @full_user.email
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mingle_macro_models
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 4
10
+ version: 1.3.4
11
+ platform: ruby
12
+ authors:
13
+ - ThoughtWorks Inc
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-10 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Wrapper models used by custom Mingle macros.
22
+ email: support@thoughtworks.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/mingle_macro_models/card_type.rb
31
+ - lib/mingle_macro_models/card_type_property_definition.rb
32
+ - lib/mingle_macro_models/project.rb
33
+ - lib/mingle_macro_models/project_variable.rb
34
+ - lib/mingle_macro_models/property_definition.rb
35
+ - lib/mingle_macro_models/property_value.rb
36
+ - lib/mingle_macro_models/user.rb
37
+ - lib/mingle_macro_models.rb
38
+ homepage: https://rubygems.org/gems/mingle_macro_models
39
+ licenses:
40
+ - MIT
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.19
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Wrapper models used by custom Mingle macros.
71
+ test_files: []
72
+