-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kyle Decot
committed
Jul 3, 2019
1 parent
5d96ecb
commit b9a6c05
Showing
4 changed files
with
36 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module AppStoreConnect | ||
class Factory | ||
UnsupportedType = Class.new(StandardError) | ||
|
||
TYPES = { | ||
'enum' => 'Enum' | ||
} | ||
}.freeze | ||
|
||
def self.type(type:, **options) | ||
case type | ||
when *TYPES.keys | ||
when *TYPES.keys | ||
klass = "AppStoreConnect::Type::#{TYPES[type]}".constantize | ||
Class.new(klass, &send(type, options)) | ||
else | ||
raise UnsupportedType, "Unsupported Type: #{type}" | ||
end | ||
end | ||
end | ||
|
||
def self.enum(options) | ||
Proc.new do |base| | ||
base.const_set("VALUES", options.fetch(:values)) | ||
end | ||
proc do |base| | ||
base.const_set('VALUES', options.fetch(:values)) | ||
end | ||
end | ||
private_class_method :enum | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module AppStoreConnect | ||
class Parser | ||
|
||
def self.parse! | ||
json = JSON.parse(File.read(File.join(__dir__, "../config/api.json"))) | ||
parse_types(json["Type"]) | ||
end | ||
json = JSON.parse(File.read(File.join(__dir__, '../config/api.json'))) | ||
|
||
parse_types(json['Type']) | ||
end | ||
|
||
def self.parse_types(types) | ||
types.each do |name, type| | ||
klass = Factory.type(type.deep_symbolize_keys) | ||
AppStoreConnect::Type::const_set(name, klass) | ||
|
||
AppStoreConnect::Type.const_set(name, klass) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
module AppStoreConnect | ||
module Type | ||
module Type | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module AppStoreConnect | ||
module Type | ||
class Enum | ||
module Type | ||
class Enum | ||
attr_reader :value | ||
|
||
def initialize(value:) | ||
@value = value | ||
end | ||
end | ||
|
||
def self.const_missing(const) | ||
if const.to_s.in?(const_get("VALUES")) | ||
return const_set(const, new(value: const.to_s)) | ||
end | ||
return const_set(const, new(value: const.to_s)) if const.to_s.in?(const_get('VALUES')) | ||
|
||
super(const) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |