horn_of_plenty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE.txt +19 -0
  5. data/README.md +36 -0
  6. data/lib/horn_of_plenty.rb +22 -0
  7. data/lib/horn_of_plenty/adapters/github/client.rb +82 -0
  8. data/lib/horn_of_plenty/adapters/github/collections/card.rb +46 -0
  9. data/lib/horn_of_plenty/adapters/github/configuration.rb +38 -0
  10. data/lib/horn_of_plenty/adapters/github/error.rb +44 -0
  11. data/lib/horn_of_plenty/adapters/github/parsers/board.rb +52 -0
  12. data/lib/horn_of_plenty/adapters/github/parsers/card.rb +91 -0
  13. data/lib/horn_of_plenty/adapters/github/parsers/issue.rb +95 -0
  14. data/lib/horn_of_plenty/adapters/github/parsers/lane.rb +50 -0
  15. data/lib/horn_of_plenty/adapters/github/parsers/pull_request.rb +38 -0
  16. data/lib/horn_of_plenty/adapters/github/queries/list_boards.rb +18 -0
  17. data/lib/horn_of_plenty/adapters/github/queries/list_cards.rb +19 -0
  18. data/lib/horn_of_plenty/adapters/github/queries/list_issues.rb +22 -0
  19. data/lib/horn_of_plenty/adapters/github/queries/list_lanes.rb +19 -0
  20. data/lib/horn_of_plenty/adapters/github/queries/list_pull_requests.rb +22 -0
  21. data/lib/horn_of_plenty/adapters/github/repositories/board.rb +24 -0
  22. data/lib/horn_of_plenty/adapters/github/repositories/card.rb +24 -0
  23. data/lib/horn_of_plenty/adapters/github/repositories/issue.rb +24 -0
  24. data/lib/horn_of_plenty/adapters/github/repositories/lane.rb +24 -0
  25. data/lib/horn_of_plenty/adapters/github/repositories/pull_request.rb +24 -0
  26. data/lib/horn_of_plenty/adapters/github/requests/list_boards.rb +50 -0
  27. data/lib/horn_of_plenty/adapters/github/requests/list_cards.rb +52 -0
  28. data/lib/horn_of_plenty/adapters/github/requests/list_issues.rb +50 -0
  29. data/lib/horn_of_plenty/adapters/github/requests/list_lanes.rb +52 -0
  30. data/lib/horn_of_plenty/adapters/github/requests/list_pull_requests.rb +50 -0
  31. data/lib/horn_of_plenty/adapters/github/response.rb +16 -0
  32. data/lib/horn_of_plenty/adapters/github/responses/list_boards.rb +17 -0
  33. data/lib/horn_of_plenty/adapters/github/responses/list_cards.rb +23 -0
  34. data/lib/horn_of_plenty/adapters/github/responses/list_issues.rb +18 -0
  35. data/lib/horn_of_plenty/adapters/github/responses/list_lanes.rb +17 -0
  36. data/lib/horn_of_plenty/adapters/github/responses/list_pull_requests.rb +17 -0
  37. data/lib/horn_of_plenty/collection.rb +60 -0
  38. data/lib/horn_of_plenty/core_ext/string.rb +95 -0
  39. data/lib/horn_of_plenty/models/board.rb +32 -0
  40. data/lib/horn_of_plenty/models/card.rb +51 -0
  41. data/lib/horn_of_plenty/models/issue.rb +46 -0
  42. data/lib/horn_of_plenty/models/lane.rb +30 -0
  43. data/lib/horn_of_plenty/models/parsable.rb +44 -0
  44. data/lib/horn_of_plenty/models/pull_request.rb +12 -0
  45. data/lib/horn_of_plenty/null_objects/board.rb +10 -0
  46. data/lib/horn_of_plenty/null_objects/card.rb +10 -0
  47. data/lib/horn_of_plenty/null_objects/issue.rb +10 -0
  48. data/lib/horn_of_plenty/null_objects/lane.rb +10 -0
  49. data/lib/horn_of_plenty/null_objects/pull_request.rb +10 -0
  50. data/lib/horn_of_plenty/paginator.rb +109 -0
  51. data/lib/horn_of_plenty/parsers/hash.rb +95 -0
  52. data/lib/horn_of_plenty/queries/fetch.rb +36 -0
  53. data/lib/horn_of_plenty/repositories/board.rb +26 -0
  54. data/lib/horn_of_plenty/repositories/card.rb +26 -0
  55. data/lib/horn_of_plenty/repositories/issue.rb +26 -0
  56. data/lib/horn_of_plenty/repositories/lane.rb +26 -0
  57. data/lib/horn_of_plenty/repositories/pull_request.rb +26 -0
  58. data/lib/horn_of_plenty/repository.rb +29 -0
  59. data/lib/horn_of_plenty/request.rb +32 -0
  60. data/lib/horn_of_plenty/response.rb +44 -0
  61. data/lib/horn_of_plenty/version.rb +4 -0
  62. data/spec/fixtures/responses/board_github.json +29 -0
  63. data/spec/fixtures/responses/card_github.json +7 -0
  64. data/spec/fixtures/responses/issue_github.json +163 -0
  65. data/spec/fixtures/responses/lane_github.json +7 -0
  66. data/spec/fixtures/responses/pull_request_github.json +361 -0
  67. data/spec/lib/horn_of_plenty/adapters/github/client_spec.rb +12 -0
  68. data/spec/lib/horn_of_plenty/adapters/github/collections/card_spec.rb +14 -0
  69. data/spec/lib/horn_of_plenty/adapters/github/configuration_spec.rb +12 -0
  70. data/spec/lib/horn_of_plenty/adapters/github/error_spec.rb +35 -0
  71. data/spec/lib/horn_of_plenty/adapters/github/parsers/board_spec.rb +39 -0
  72. data/spec/lib/horn_of_plenty/adapters/github/parsers/card_spec.rb +64 -0
  73. data/spec/lib/horn_of_plenty/adapters/github/parsers/issue_spec.rb +47 -0
  74. data/spec/lib/horn_of_plenty/adapters/github/parsers/lane_spec.rb +38 -0
  75. data/spec/lib/horn_of_plenty/adapters/github/parsers/pull_request_spec.rb +50 -0
  76. data/spec/lib/horn_of_plenty/adapters/github/queries/list_boards_spec.rb +19 -0
  77. data/spec/lib/horn_of_plenty/adapters/github/queries/list_cards_spec.rb +19 -0
  78. data/spec/lib/horn_of_plenty/adapters/github/queries/list_issues_spec.rb +19 -0
  79. data/spec/lib/horn_of_plenty/adapters/github/queries/list_lanes_spec.rb +19 -0
  80. data/spec/lib/horn_of_plenty/adapters/github/queries/list_pull_requests_spec.rb +19 -0
  81. data/spec/lib/horn_of_plenty/adapters/github/repositories/board_spec.rb +22 -0
  82. data/spec/lib/horn_of_plenty/adapters/github/repositories/card_spec.rb +67 -0
  83. data/spec/lib/horn_of_plenty/adapters/github/repositories/issue_spec.rb +22 -0
  84. data/spec/lib/horn_of_plenty/adapters/github/repositories/lane_spec.rb +25 -0
  85. data/spec/lib/horn_of_plenty/adapters/github/repositories/pull_request_spec.rb +24 -0
  86. data/spec/lib/horn_of_plenty/adapters/github/requests/list_boards_spec.rb +42 -0
  87. data/spec/lib/horn_of_plenty/adapters/github/requests/list_cards_spec.rb +51 -0
  88. data/spec/lib/horn_of_plenty/adapters/github/requests/list_issues_spec.rb +42 -0
  89. data/spec/lib/horn_of_plenty/adapters/github/requests/list_lanes_spec.rb +51 -0
  90. data/spec/lib/horn_of_plenty/adapters/github/requests/list_pull_requests_spec.rb +42 -0
  91. data/spec/lib/horn_of_plenty/adapters/github/responses/list_boards_spec.rb +78 -0
  92. data/spec/lib/horn_of_plenty/adapters/github/responses/list_cards_spec.rb +86 -0
  93. data/spec/lib/horn_of_plenty/adapters/github/responses/list_issues_spec.rb +104 -0
  94. data/spec/lib/horn_of_plenty/adapters/github/responses/list_lanes_spec.rb +86 -0
  95. data/spec/lib/horn_of_plenty/adapters/github/responses/list_pull_requests_spec.rb +109 -0
  96. data/spec/lib/horn_of_plenty/models/board_spec.rb +10 -0
  97. data/spec/lib/horn_of_plenty/models/card_spec.rb +10 -0
  98. data/spec/lib/horn_of_plenty/models/issue_spec.rb +10 -0
  99. data/spec/lib/horn_of_plenty/models/lane_spec.rb +10 -0
  100. data/spec/lib/horn_of_plenty/models/pull_request_spec.rb +10 -0
  101. data/spec/lib/horn_of_plenty/null_objects/board_spec.rb +10 -0
  102. data/spec/lib/horn_of_plenty/null_objects/card_spec.rb +10 -0
  103. data/spec/lib/horn_of_plenty/null_objects/issue_spec.rb +10 -0
  104. data/spec/lib/horn_of_plenty/null_objects/lane_spec.rb +10 -0
  105. data/spec/lib/horn_of_plenty/null_objects/pull_request_spec.rb +10 -0
  106. data/spec/lib/horn_of_plenty/queries/fetch_spec.rb +15 -0
  107. data/spec/lib/horn_of_plenty/repositories/board_spec.rb +48 -0
  108. data/spec/lib/horn_of_plenty/repositories/card_spec.rb +51 -0
  109. data/spec/lib/horn_of_plenty/repositories/issue_spec.rb +48 -0
  110. data/spec/lib/horn_of_plenty/repositories/lane_spec.rb +51 -0
  111. data/spec/lib/horn_of_plenty/repositories/pull_request_spec.rb +50 -0
  112. data/spec/support/patterns.rb +1 -0
  113. metadata +396 -0
  114. metadata.gz.sig +0 -0
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/request'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Requests
8
+ class ListCards < HornOfPlenty::Request
9
+ attr_accessor :format,
10
+ :pagination,
11
+ :query,
12
+ :repository
13
+
14
+ def initialize(format: 'raw',
15
+ pagination: {},
16
+ query: {},
17
+ repository:)
18
+
19
+ self.format = format
20
+ self.pagination = pagination
21
+ self.query = query
22
+ self.repository = repository
23
+ end
24
+
25
+ def method
26
+ 'get'
27
+ end
28
+
29
+ def path
30
+ if query[:id]
31
+ "repos/#{repository}/projects/columns/cards/#{query[:id]}"
32
+ elsif query[:lane_id]
33
+ "repos/#{repository}/projects/columns/#{query[:lane_id]}/cards"
34
+ end
35
+ end
36
+
37
+ def to_h
38
+ @to_h ||= query_class.new(query).to_h.
39
+ merge(pagination_hash)
40
+ end
41
+ alias to_params to_h
42
+
43
+ private
44
+
45
+ def pagination_hash
46
+ pagination.to_h
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/request'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Requests
8
+ class ListIssues < HornOfPlenty::Request
9
+ attr_accessor :format,
10
+ :pagination,
11
+ :query,
12
+ :repository
13
+
14
+ def initialize(format: 'raw',
15
+ pagination: {},
16
+ query: {},
17
+ repository:)
18
+
19
+ self.format = format
20
+ self.pagination = pagination
21
+ self.query = query
22
+ self.repository = repository
23
+ end
24
+
25
+ def method
26
+ 'get'
27
+ end
28
+
29
+ def path
30
+ return "repos/#{repository}/issues" unless query[:id]
31
+
32
+ "repos/#{repository}/issues/#{query[:id]}"
33
+ end
34
+
35
+ def to_h
36
+ @to_h ||= query_class.new(query).to_h.
37
+ merge(pagination_hash)
38
+ end
39
+ alias to_params to_h
40
+
41
+ private
42
+
43
+ def pagination_hash
44
+ pagination.to_h
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/request'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Requests
8
+ class ListLanes < HornOfPlenty::Request
9
+ attr_accessor :format,
10
+ :pagination,
11
+ :query,
12
+ :repository
13
+
14
+ def initialize(format: 'raw',
15
+ pagination: {},
16
+ query: {},
17
+ repository:)
18
+
19
+ self.format = format
20
+ self.pagination = pagination
21
+ self.query = query
22
+ self.repository = repository
23
+ end
24
+
25
+ def method
26
+ 'get'
27
+ end
28
+
29
+ def path
30
+ if query[:id]
31
+ "repos/#{repository}/projects/columns/#{query[:id]}"
32
+ elsif query[:board_id]
33
+ "repos/#{repository}/projects/#{query[:board_id]}/columns"
34
+ end
35
+ end
36
+
37
+ def to_h
38
+ @to_h ||= query_class.new(query).to_h.
39
+ merge(pagination_hash)
40
+ end
41
+ alias to_params to_h
42
+
43
+ private
44
+
45
+ def pagination_hash
46
+ pagination.to_h
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/request'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Requests
8
+ class ListPullRequests < HornOfPlenty::Request
9
+ attr_accessor :format,
10
+ :pagination,
11
+ :query,
12
+ :repository
13
+
14
+ def initialize(format: 'raw',
15
+ pagination: {},
16
+ query: {},
17
+ repository:)
18
+
19
+ self.format = format
20
+ self.pagination = pagination
21
+ self.query = query
22
+ self.repository = repository
23
+ end
24
+
25
+ def method
26
+ 'get'
27
+ end
28
+
29
+ def path
30
+ return "repos/#{repository}/pulls" unless query[:id]
31
+
32
+ "repos/#{repository}/pulls/#{query[:id]}"
33
+ end
34
+
35
+ def to_h
36
+ @to_h ||= query_class.new(query).to_h.
37
+ merge(pagination_hash)
38
+ end
39
+ alias to_params to_h
40
+
41
+ private
42
+
43
+ def pagination_hash
44
+ pagination.to_h
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/response'
3
+ require 'horn_of_plenty/adapters/github/error'
4
+
5
+ module HornOfPlenty
6
+ module Adapters
7
+ module Github
8
+ class Response < HornOfPlenty::Response
9
+ def error
10
+ Github::Error.lookup(status_code,
11
+ status_message)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/response'
3
+ require 'horn_of_plenty/adapters/github/parsers/board'
4
+
5
+ module HornOfPlenty
6
+ module Adapters
7
+ module Github
8
+ module Responses
9
+ class ListBoards < Github::Response
10
+ def parser_class
11
+ @parser_class ||= Parsers::Board
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/response'
3
+ require 'horn_of_plenty/adapters/github/collections/card'
4
+ require 'horn_of_plenty/adapters/github/parsers/card'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Responses
10
+ class ListCards < Github::Response
11
+ def result
12
+ @result ||= Collections::Card.new(items: items,
13
+ parser: parser_class)
14
+ end
15
+
16
+ def parser_class
17
+ @parser_class ||= Parsers::Card
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ # require 'horn_of_plenty/adapters/github/parsers/issue'
3
+ require 'horn_of_plenty/adapters/github/response'
4
+ require 'horn_of_plenty/adapters/github/parsers/issue'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Responses
10
+ class ListIssues < Github::Response
11
+ def parser_class
12
+ @parser_class ||= Parsers::Issue
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/response'
3
+ require 'horn_of_plenty/adapters/github/parsers/lane'
4
+
5
+ module HornOfPlenty
6
+ module Adapters
7
+ module Github
8
+ module Responses
9
+ class ListLanes < Github::Response
10
+ def parser_class
11
+ @parser_class ||= Parsers::Lane
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/response'
3
+ require 'horn_of_plenty/adapters/github/parsers/pull_request'
4
+
5
+ module HornOfPlenty
6
+ module Adapters
7
+ module Github
8
+ module Responses
9
+ class ListPullRequests < Github::Response
10
+ def parser_class
11
+ @parser_class ||= Parsers::PullRequest
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'forwardable'
3
+
4
+ module HornOfPlenty
5
+ class Collection
6
+ include Enumerable
7
+ extend Forwardable
8
+
9
+ def_delegators :raw_items,
10
+ :length,
11
+ :size,
12
+ :count,
13
+ :empty?
14
+
15
+ def initialize(items:, parser:)
16
+ self.raw_items = items
17
+ self.parser = parser
18
+ end
19
+
20
+ def [](index)
21
+ items[index] ||= transform(raw_items[index])
22
+ end
23
+
24
+ def first
25
+ items[0] ||= transform(raw_items[0])
26
+ end
27
+
28
+ def shift(*args)
29
+ raw_items.shift(*args)
30
+ items.shift(*args)
31
+ end
32
+
33
+ def pop(*args)
34
+ raw_items.pop(*args)
35
+ items.pop(*args)
36
+ end
37
+
38
+ def each
39
+ raw_items.each_with_index do |raw_item, index|
40
+ items[index] = items[index] || transform(raw_item)
41
+
42
+ yield items[index]
43
+ end
44
+ end
45
+
46
+ protected
47
+
48
+ attr_accessor :raw_items,
49
+ :items,
50
+ :parser
51
+
52
+ def transform(raw_item)
53
+ parser.to_model(raw_item)
54
+ end
55
+
56
+ def items
57
+ @items ||= []
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+ module HornOfPlenty
3
+ module CoreExt
4
+ class String
5
+ # rubocop:disable Metrics/LineLength
6
+ SINGULARIZATION_RULES = [
7
+ [/(database)s$/i, '\1'],
8
+ [/(quiz)zes$/i, '\1'],
9
+ [/(matr)ices$/i, '\1ix'],
10
+ [/(vert|ind)ices$/i, '\1ex'],
11
+ [/^(ox)en/i, '\1'],
12
+ [/(alias|status)(es)?$/i, '\1'],
13
+ [/(octop|vir)(us|i)$/i, '\1us'],
14
+ [/^(a)x[ie]s$/i, '\1xis'],
15
+ [/(cris|test)(is|es)$/i, '\1is'],
16
+ [/(shoe)s$/i, '\1'],
17
+ [/(o)es$/i, '\1'],
18
+ [/(bus)(es)?$/i, '\1'],
19
+ [/^(m|l)ice$/i, '\1ouse'],
20
+ [/(x|ch|ss|sh)es$/i, '\1'],
21
+ [/(m)ovies$/i, '\1ovie'],
22
+ [/(s)eries$/i, '\1eries'],
23
+ [/([^aeiouy]|qu)ies$/i, '\1y'],
24
+ [/([lr])ves$/i, '\1f'],
25
+ [/(tive)s$/i, '\1'],
26
+ [/(hive)s$/i, '\1'],
27
+ [/([^f])ves$/i, '\1fe'],
28
+ [/(^analy)(sis|ses)$/i, '\1sis'],
29
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '\1sis'],
30
+ [/([ti])a$/i, '\1um'],
31
+ [/(n)ews$/i, '\1ews'],
32
+ [/(ss)$/i, '\1'],
33
+ [/s$/i, ''],
34
+ ].freeze
35
+ # rubocop:enable Metrics/LineLength
36
+
37
+ def self.camelize(other, uppercase_first_letter = true)
38
+ string = if uppercase_first_letter
39
+ other.sub(/^[a-z\d]*/) do
40
+ $&.capitalize
41
+ end
42
+ else
43
+ other.sub(/^(?:(?=\b|[A-Z_])|\w)/) do
44
+ $&.downcase
45
+ end
46
+ end
47
+
48
+ string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
49
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
50
+ end
51
+
52
+ string.gsub!(%r{/}, '::')
53
+
54
+ string
55
+ end
56
+
57
+ def self.constantize(other)
58
+ names = other.split('::')
59
+ names.shift if names.empty? || names.first.empty?
60
+
61
+ constant = Object
62
+
63
+ names.each do |name|
64
+ constant = if constant.const_defined?(name)
65
+ constant.const_get(name)
66
+ else
67
+ constant.const_missing(name)
68
+ end
69
+ end
70
+
71
+ constant
72
+ end
73
+
74
+ def self.underscore(other)
75
+ word = other.to_s.dup
76
+ word.gsub!(/::/, '/')
77
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
78
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
79
+ word.tr!('-', '_')
80
+ word.downcase!
81
+ word
82
+ end
83
+
84
+ def self.singularize(word)
85
+ result = word.to_s.dup
86
+
87
+ SINGULARIZATION_RULES.each do |(rule, replacement)|
88
+ break if result.sub!(rule, replacement)
89
+ end
90
+
91
+ result
92
+ end
93
+ end
94
+ end
95
+ end