Module: Nomen

Defined in:
lib/nomen.rb,
lib/nomen/item.rb,
lib/nomen/relation.rb,
lib/nomen/migrator.rb,
lib/nomen/reference.rb,
lib/nomen/migration.rb,
lib/nomen/reflection.rb,
lib/nomen/nomenclature.rb,
lib/nomen/migrator/model.rb,
lib/nomen/migration/base.rb,
lib/nomen/property_nature.rb,
lib/nomen/nomenclature_set.rb,
lib/nomen/migration/actions.rb,
lib/nomen/migrator/reference.rb,
lib/nomen/migrator/translation.rb,
lib/nomen/migration/actions/base.rb,
lib/nomen/migration/actions/item_change.rb,
lib/nomen/migration/actions/item_merging.rb,
lib/nomen/migration/actions/item_removal.rb,
lib/nomen/migration/actions/item_creation.rb,
lib/nomen/migration/actions/property_creation.rb,
lib/nomen/migration/actions/nomenclature_change.rb,
lib/nomen/migration/actions/nomenclature_removal.rb,
lib/nomen/migration/actions/nomenclature_creation.rb

Defined Under Namespace

Modules: Migration, Migrator Classes: Error, InvalidProperty, InvalidPropertyNature, Item, ItemNotFound, MissingChoices, MissingNomenclature, Nomenclature, NomenclatureSet, PropertyNature, Reference, Reflection, Relation

Constant Summary collapse

XMLNS =
'http://www.ekylibre.org/XML/2013/nomenclatures'.freeze
NS_SEPARATOR =
'-'.freeze
PROPERTY_TYPES =
[:boolean, :item, :item_list, :choice, :choice_list, :string_list, :date, :decimal, :integer, :nomenclature, :string, :symbol].freeze

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Give access to named nomenclatures


87
88
89
# File 'lib/nomen.rb', line 87

def [](name)
  @@set[name]
end

.allObject


82
83
84
# File 'lib/nomen.rb', line 82

def all
  @@set.nomenclatures
end

.const_missing(name) ⇒ Object

Returns the matching nomenclature


122
123
124
125
126
# File 'lib/nomen.rb', line 122

def const_missing(name)
  n = name.to_s.tableize
  return self[n] if @@set.exist?(n)
  super
end

.each(&block) ⇒ Object

Browse all nomenclatures


108
109
110
# File 'lib/nomen.rb', line 108

def each(&block)
  @@set.each(&block)
end

.find(*args) ⇒ Object

Give access to named nomenclatures


92
93
94
95
96
97
98
99
100
101
# File 'lib/nomen.rb', line 92

def find(*args)
  options = args.extract_options!
  name = args.shift
  if args.empty?
    return @@set[name]
  elsif args.size == 1
    return @@set[name].find(args.shift) if @@set[name]
  end
  nil
end

.find_or_initialize(name) ⇒ Object


103
104
105
# File 'lib/nomen.rb', line 103

def find_or_initialize(name)
  @@set[name] || Nomenclature.new(name, set: @@set)
end

.loadObject


112
113
114
115
116
117
118
119
# File 'lib/nomen.rb', line 112

def load
  @@set = if reference_path.exist?
            NomenclatureSet.load_file(reference_path)
          else
            NomenclatureSet.new
          end
  Rails.logger.info 'Loaded nomenclatures: ' + Nomen.names.to_sentence
end

.migrationsObject

Returns list of Nomen::Migration


63
64
65
66
67
# File 'lib/nomen.rb', line 63

def migrations
  Dir.glob(migrations_path.join('*.xml')).sort.collect do |f|
    Nomen::Migration::Base.parse(Pathname.new(f))
  end
end

.migrations_pathObject


39
40
41
# File 'lib/nomen.rb', line 39

def migrations_path
  root_path.join('migrate')
end

.missing_migrationsObject

Returns list of migrations since last done


70
71
72
73
74
75
# File 'lib/nomen.rb', line 70

def missing_migrations
  last_version = reference_version
  migrations.select do |m|
    m.number > last_version
  end
end

.namesObject

Returns the names of the nomenclatures


78
79
80
# File 'lib/nomen.rb', line 78

def names
  @@set.nomenclature_names
end

.reference_documentObject


53
54
55
56
57
58
59
60
# File 'lib/nomen.rb', line 53

def reference_document
  f = File.open(reference_path, 'rb')
  document = Nokogiri::XML(f) do |config|
    config.strict.nonet.noblanks.noent
  end
  f.close
  document
end

.reference_pathObject


43
44
45
# File 'lib/nomen.rb', line 43

def reference_path
  root_path.join('db.xml')
end

.reference_versionObject

Returns version of DB


48
49
50
51
# File 'lib/nomen.rb', line 48

def reference_version
  return 0 unless reference_path.exist?
  reference_document.root['version'].to_i
end

.root_pathObject


35
36
37
# File 'lib/nomen.rb', line 35

def root_path
  Rails.root.join('db', 'nomenclatures')
end