Class: ActiveFacts::Generators::Metadata::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/generators/metadata/json.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(vocabulary, *options) ⇒ JSON

Returns a new instance of JSON.



17
18
19
20
21
# File 'lib/activefacts/generators/metadata/json.rb', line 17

def initialize(vocabulary, *options)
  @vocabulary = vocabulary
  @vocabulary = @vocabulary.Vocabulary.values[0] if ActiveFacts::API::Constellation === @vocabulary
  options.each{|option| set_option(option) }
end

Instance Method Details

#generate(out = $>) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/activefacts/generators/metadata/json.rb', line 26

def generate(out = $>)
	  @metadata = {"types" => {}}

  object_types_dump

	  out.puts ::JSON.pretty_generate(@metadata)
end

#object_types_dumpObject

Store the metadata for all types into the types section of the @metadata hash



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/activefacts/generators/metadata/json.rb', line 35

def object_types_dump
  types = @metadata["types"]

  # Compute the relational mapping if not already done:
  @tables ||= @vocabulary.tables

  @vocabulary.all_object_type.
  sort_by{|c| c.name}.each do |o|
    object_type = o.

    types[o.name] = object_type if object_type
  end
end

#set_option(option) ⇒ Object



23
24
# File 'lib/activefacts/generators/metadata/json.rb', line 23

def set_option(option)
end