Skip to content

Commit

Permalink
Fix Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Decot committed Jul 3, 2019
1 parent 5d96ecb commit b9a6c05
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
18 changes: 10 additions & 8 deletions lib/app_store_connect/factory.rb
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
21 changes: 11 additions & 10 deletions lib/app_store_connect/parser.rb
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
6 changes: 4 additions & 2 deletions lib/app_store_connect/type.rb
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
22 changes: 11 additions & 11 deletions lib/app_store_connect/type/enum.rb
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

0 comments on commit b9a6c05

Please sign in to comment.