Skip to content

Commit

Permalink
let services specify their schemas in code.
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Jun 21, 2011
1 parent 689e1ab commit 7785065
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions lib/service.rb
Expand Up @@ -32,6 +32,93 @@ def receive(event, data, payload = nil)
end
end

# Gets the current schema for the data attributes that this Service
# expects. This schema is used to generate the GitHub repository admin
# interface. The attribute types loosely to HTML input elements.
#
# Example:
#
# class FooService < Service
# string :token
# end
#
# FooService.schema
# # => [[:string, :token]]
#
# Returns an Array of [Symbol, String] tuples.
def schema
@schema ||= []
end

# Public: Adds the given attributes as String attributes in the Service's
# schema.
#
# Example:
#
# class FooService < Service
# string :token
# end
#
# FooService.schema
# # => [[:string, :token]]
#
# *attrs - Array of Symbol attribute names.
#
# Returns nothing.
def string(*attrs)
add_to_schema :string, attrs
end

# Public: Adds the given attributes as Password attributes in the Service's
# schema.
#
# Example:
#
# class FooService < Service
# password :token
# end
#
# FooService.schema
# # => [[:password, :token]]
#
# *attrs - Array of Symbol attribute names.
#
# Returns nothing.
def password(*attrs)
add_to_schema :password, attrs
end

# Public: Adds the given attributes as Boolean attributes in the Service's
# schema.
#
# Example:
#
# class FooService < Service
# boolean :digest
# end
#
# FooService.schema
# # => [[:boolean, :digest]]
#
# *attrs - Array of Symbol attribute names.
#
# Returns nothing.
def boolean(*attrs)
add_to_schema :boolean, attrs
end

# Adds the given attributes to the Service's data schema.
#
# type - A Symbol specifying the type: :string, :password, :boolean.
# attrs - Array of Symbol attribute names.
#
# Returns nothing.
def add_to_schema(type, attrs)
attrs.each do |attr|
schema << [type, attr.to_sym]
end
end

# Gets the String name that identifies this Service type.
#
# Returns a String.
Expand Down

0 comments on commit 7785065

Please sign in to comment.