Sha256: 665859aff359422aeb9bbe3bcede716588fa73a8a1f7d4f90322fdda34ed81b3

Contents?: true

Size: 1.85 KB

Versions: 7

Compression:

Stored size: 1.85 KB

Contents

module Hyperstack
  define_setting :public_model_directories, [File.join('app','hyperstack','models'), File.join('app','models','public')]
end

module ActiveRecord
  # adds method to get the HyperMesh public column types
  # this works because the public folder is currently required to be eager loaded.
  class Base
    def self.public_columns_hash
      return @public_columns_hash if @public_columns_hash && Rails.env.production?
      files = []
      Hyperstack.public_model_directories.each do |dir|
        dir_length = Rails.root.join(dir).to_s.length + 1
        Dir.glob(Rails.root.join(dir, '**', '*.rb')).each do |file|
          require_dependency(file) # still the file is loaded to make sure for development and test env
          files << file[dir_length..-4]
        end
      end
      @public_columns_hash = {}
      # descendants only works for already loaded models!
      descendants.each do |model|
        if files.include?(model.name.underscore) && model.name.underscore != 'application_record'
          @public_columns_hash[model.name] = model.columns_hash rescue nil # why rescue?
        end
        # begin
        #   @public_columns_hash[model.name] = model.columns_hash if model.table_name
        # rescue Exception => e
        #   binding.pry
        #   @public_columns_hash = nil
        #   raise $!, "Could not read 'columns_hash' for #{model}: #{$!}", $!.backtrace
        # end if files.include?(model.name.underscore) && model.name.underscore != 'application_record'
      end
      @public_columns_hash
    end

    def self.public_columns_hash_as_json
      return @public_columns_hash_json if @public_columns_hash_json && Rails.env.production?
      pch = public_columns_hash
      return @public_columns_hash_json if @prev_public_columns_hash == pch
      @prev_public_columns_hash = pch
      @public_columns_hash_json = pch.to_json
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyper-model-1.0.alpha1.6 lib/reactive_record/active_record/public_columns_hash.rb
hyper-model-1.0.alpha1.5 lib/reactive_record/active_record/public_columns_hash.rb
hyper-model-1.0.alpha1.4 lib/reactive_record/active_record/public_columns_hash.rb
hyper-model-1.0.alpha1.3 lib/reactive_record/active_record/public_columns_hash.rb
hyper-model-1.0.alpha1.2 lib/reactive_record/active_record/public_columns_hash.rb
hyper-model-1.0.alpha1.1 lib/reactive_record/active_record/public_columns_hash.rb
hyper-model-1.0.alpha1 lib/reactive_record/active_record/public_columns_hash.rb