Sha256: e8dfda6746ef538f720cfaf77328e5a0b2ef49c22180717b40a05a3730d7ec2a

Contents?: true

Size: 1.24 KB

Versions: 27

Compression:

Stored size: 1.24 KB

Contents

require 'spout/models/variable'
require 'spout/models/domain'
require 'spout/models/form'

module Spout
  module Models
    class Dictionary
      attr_accessor :variables, :domains, :forms
      attr_accessor :app_path

      attr_reader :variable_files, :domain_files, :form_files

      def initialize(app_path)
        @app_path = app_path

        @variable_files = json_files('variables')
        @domain_files = json_files('domains')
        @form_files = json_files('forms')

        @variables = []
        @domains = []
        @forms = []
      end

      def load_all!
        load_variables!
        load_domains!
        load_forms!
        self
      end

      def load_variables!
        load_type!('Variable')
      end

      def load_domains!
        load_type!('Domain')
      end

      def load_forms!
        load_type!('Form')
      end

      private

      def json_files(type)
        Dir.glob(File.join(@app_path, type, "**", "*.json"))
      end

      def load_type!(method)
        results = instance_variable_get("@#{method.downcase}_files").collect do |file|
          Object.const_get("Spout::Models::#{method}").new(file, @app_path)
        end

        instance_variable_set("@#{method.downcase}s", results)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
spout-0.10.2 lib/spout/models/dictionary.rb
spout-0.10.1 lib/spout/models/dictionary.rb
spout-0.10.0 lib/spout/models/dictionary.rb
spout-0.10.0.rc3 lib/spout/models/dictionary.rb
spout-0.10.0.rc2 lib/spout/models/dictionary.rb
spout-0.10.0.rc lib/spout/models/dictionary.rb
spout-0.10.0.beta10 lib/spout/models/dictionary.rb
spout-0.10.0.beta9 lib/spout/models/dictionary.rb
spout-0.10.0.beta8 lib/spout/models/dictionary.rb
spout-0.10.0.beta7 lib/spout/models/dictionary.rb
spout-0.10.0.beta6 lib/spout/models/dictionary.rb
spout-0.10.0.beta4 lib/spout/models/dictionary.rb
spout-0.10.0.beta3 lib/spout/models/dictionary.rb
spout-0.10.0.beta2 lib/spout/models/dictionary.rb
spout-0.10.0.beta1 lib/spout/models/dictionary.rb
spout-0.9.1 lib/spout/models/dictionary.rb
spout-0.9.0 lib/spout/models/dictionary.rb
spout-0.9.0.rc lib/spout/models/dictionary.rb
spout-0.9.0.beta2 lib/spout/models/dictionary.rb
spout-0.9.0.beta1 lib/spout/models/dictionary.rb