lib/grape-apiary/config.rb in grape-apiary-0.0.2 vs lib/grape-apiary/config.rb in grape-apiary-0.0.3
- old
+ new
@@ -4,10 +4,11 @@
:host,
:name,
:description,
:request_headers,
:response_headers,
+ :example_id_type,
:resource_exclusion
]
class << self
attr_accessor(*SETTINGS)
@@ -20,9 +21,38 @@
@response_headers ||= []
end
def resource_exclusion
@resource_exclusion ||= []
+ end
+
+ def supported_id_types
+ [:integer, :uuid, :bson]
+ end
+
+ def example_id_type=(value)
+ fail UnsupportedIDType unless supported_id_types.include?(value)
+
+ if value.to_sym == :bson && !Object.const_defined?('BSON')
+ fail BSONNotDefinied
+ end
+
+ @example_id_type = value
+ end
+
+ def example_id_type
+ @example_id_type ||= :integer
+ end
+
+ def generate_id
+ case example_id_type
+ when :integer
+ SecureRandom.random_number(1000)
+ when :uuid
+ SecureRandom.uuid
+ when :bson
+ BSON::ObjectId.new.to_s
+ end
end
end
end
end