Class: Ark::Schema

Inherits:
Object
  • Object
show all
Includes:
Validations::Schema
Defined in:
lib/ark/schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

Returns a new instance of Schema.



22
23
24
# File 'lib/ark/schema.rb', line 22

def initialize
  @db = Ark::Repo.db || Ark::Repo.connect
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



6
7
8
# File 'lib/ark/schema.rb', line 6

def db
  @db
end

#definitionObject

Returns the value of attribute definition.



5
6
7
# File 'lib/ark/schema.rb', line 5

def definition
  @definition
end

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/ark/schema.rb', line 5

def errors
  @errors
end

#parsed_schemaObject (readonly)

Returns the value of attribute parsed_schema.



6
7
8
# File 'lib/ark/schema.rb', line 6

def parsed_schema
  @parsed_schema
end

Class Method Details

.add(definition) ⇒ Object



10
11
12
13
14
# File 'lib/ark/schema.rb', line 10

def add(definition)
  s = self.new
  s.definition = definition
  s.save
end

.basepathObject



16
17
18
# File 'lib/ark/schema.rb', line 16

def basepath
  "_schema"
end

Instance Method Details

#saveObject



30
31
32
33
34
35
36
# File 'lib/ark/schema.rb', line 30

def save
  if valid?
    @db.set("#{self.class.basepath}/#{@parsed_schema['id']}.json", @definition, "Adding schema - #{@parsed_schema['id']}")
  else
    false
  end
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ark/schema.rb', line 26

def valid?
  validate_schema
end