Sha256: 746ad90c8e19f89be0ce1754f68b2b3234f52cd5ab5947dc5b7b6a027c76f059

Contents?: true

Size: 575 Bytes

Versions: 10

Compression:

Stored size: 575 Bytes

Contents

module UnifiedDB
  module Result
    class Base
      
      def self.allowed_keys; []; end
      
      def initialize(params)
        allowed_keys.each do |key|
          instance_variable_set("@#{key}", params[key])
        end
      end
      
      def to_h
        allowed_keys.inject({}) { |hash, key| hash[key] = instance_variable_get("@#{key}"); hash }
      end
      
      def to_json(*args)
        UnifiedDB.json_encoder.encode to_h
      end
      
      private
      
      def allowed_keys
        self.class.allowed_keys
      end
      
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
unified_db-0.2.7 lib/unified_db/result/base.rb
unified_db-0.2.6 lib/unified_db/result/base.rb
unified_db-0.2.5 lib/unified_db/result/base.rb
unified_db-0.2.4 lib/unified_db/result/base.rb
unified_db-0.2.3 lib/unified_db/result/base.rb
unified_db-0.2.2 lib/unified_db/result/base.rb
unified_db-0.2.1 lib/unified_db/result/base.rb
unified_db-0.2.0 lib/unified_db/result/base.rb
unified_db-0.1.1 lib/unified_db/result/base.rb
unified_db-0.1.0 lib/unified_db/result/base.rb