Class: RiakJson::CollectionSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/riak_json/collection_schema.rb

Overview

Helper object for creating RiakJson schemas.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollectionSchema

Returns a new instance of CollectionSchema.



26
27
28
# File 'lib/riak_json/collection_schema.rb', line 26

def initialize
  @fields = []
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



24
25
26
# File 'lib/riak_json/collection_schema.rb', line 24

def fields
  @fields
end

Class Method Details

.valid_field_typesObject



61
62
63
# File 'lib/riak_json/collection_schema.rb', line 61

def self.valid_field_types
  [:text, :string, :multi_string, :integer, :geo]
end

Instance Method Details

#add_field(field_type, field_name, required = false) ⇒ Object



30
31
32
33
34
35
# File 'lib/riak_json/collection_schema.rb', line 30

def add_field(field_type, field_name, required=false)
  unless self.class.valid_field_types.include? field_type.to_sym
    raise Exception, "Invalid field type"
  end
  self.fields << { name: field_name.to_s, type: field_type.to_s, require: required }
end

#add_geo_field(field_name, required = false) ⇒ Object



37
38
39
# File 'lib/riak_json/collection_schema.rb', line 37

def add_geo_field(field_name, required=false)
  self.add_field(:geo, field_name, required)
end

#add_integer_field(field_name, required = false) ⇒ Object



41
42
43
# File 'lib/riak_json/collection_schema.rb', line 41

def add_integer_field(field_name, required=false)
  self.add_field(:integer, field_name, required)
end

#add_multi_string_field(field_name, required = false) ⇒ Object



45
46
47
# File 'lib/riak_json/collection_schema.rb', line 45

def add_multi_string_field(field_name, required=false)
  self.add_field(:multi_string, field_name, required)
end

#add_string_field(field_name, required = false) ⇒ Object



49
50
51
# File 'lib/riak_json/collection_schema.rb', line 49

def add_string_field(field_name, required=false)
  self.add_field(:string, field_name, required)
end

#add_text_field(field_name, required = false) ⇒ Object



53
54
55
# File 'lib/riak_json/collection_schema.rb', line 53

def add_text_field(field_name, required=false)
  self.add_field(:text, field_name, required)
end

#buildObject



57
58
59
# File 'lib/riak_json/collection_schema.rb', line 57

def build
  self.fields.to_json
end