Navigation Menu

Skip to content

Commit

Permalink
schema response: support method access to command information
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 25, 2017
1 parent 51a3fe0 commit a1a179c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/groonga/client/response/schema.rb
Expand Up @@ -147,6 +147,11 @@ class ValueType < ::Hash
include Hashie::Extensions::MethodAccess
end

class Command < ::Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::MethodAccess
end

class Index < ::Hash
include Hashie::Extensions::MethodAccess

Expand Down Expand Up @@ -204,6 +209,8 @@ def []=(key, value)
when :value_type
value = ValueType.new(value) unless value.nil?
super(key, value)
when :command
super(key, Command.new(value))
else
super
end
Expand Down Expand Up @@ -243,6 +250,8 @@ def []=(key, value)
super(key, coerce_columns(value))
when :indexes
super(key, coerce_indexes(value))
when :command
super(key, Command.new(value))
else
super
end
Expand Down
54 changes: 54 additions & 0 deletions test/response/test-schema.rb
Expand Up @@ -263,6 +263,30 @@ def test_indexes
end
end
end

def test_command
body = {
"tables" => {
"Users" => {
"command" => {
"name" => "table_create",
"arguments" => {
"name" => "Users",
"flags" => "TABLE_HASH_KEY",
"key_type" => "ShortText",
},
}
}
}
}
response = create_response(body)
assert_equal({
"name" => "Users",
"flags" => "TABLE_HASH_KEY",
"key_type" => "ShortText",
},
response.tables["Users"].command.arguments)
end
end

class TestColumn < self
Expand Down Expand Up @@ -410,6 +434,36 @@ def test_indexes
end
end
end

def test_command
body = {
"tables" => {
"Users" => {
"columns" => {
"name" => {
"command" => {
"name" => "column_create",
"arguments" => {
"table" => "Users",
"name" => "name",
"flags" => "COLUMN_SCALAR",
"type" => "ShortText",
},
}
}
}
}
}
}
response = create_response(body)
assert_equal({
"table" => "Users",
"name" => "name",
"flags" => "COLUMN_SCALAR",
"type" => "ShortText",
},
response.tables["Users"].columns["name"].command.arguments)
end
end

class TestIndex < self
Expand Down

0 comments on commit a1a179c

Please sign in to comment.