Navigation Menu

Skip to content

Commit

Permalink
Normalize role
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 6, 2015
1 parent 7a51b79 commit ff421d5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/droonga/node_metadata.rb
Expand Up @@ -23,6 +23,17 @@ module Role
SERVICE_PROVIDER = "service-provider"
ABSORB_SOURCE = "absorb-source"
ABSORB_DESTINATION = "absorb-destination"

ROLES = [
SERVICE_PROVIDER,
ABSORB_SOURCE,
ABSORB_DESTINATION,
]

module_function
def valid?(role)
ROLES.include?(role)
end
end

def initialize
Expand Down Expand Up @@ -52,11 +63,11 @@ def delete(key)
end

def role
get(:role) || Role::SERVICE_PROVIDER
normalize_role(get(:role))
end

def role=(new_role)
set(:role, new_role)
set(:role, normalize_role(new_role))
end

def reload
Expand All @@ -68,6 +79,11 @@ def normalize_key(key)
key.to_sym
end

def normalize_role(role)
role = Role::SERVICE_PROVIDER unless Role.valid?(role)
role
end

def metadata_file
@metadata_file ||= Path.node_metadata
end
Expand Down

0 comments on commit ff421d5

Please sign in to comment.