Sha256: 234702397dab930a10093e5c9df0bf7252cc3daaa3bf66b2ddc72d470222ae1c

Contents?: true

Size: 863 Bytes

Versions: 52

Compression:

Stored size: 863 Bytes

Contents

module EY
  module Model
    class ApiStruct < Struct

      def self.new(*args, &block)
        super(*args) do |*block_args|
          block.call(*block_args) if block

          def self.from_array(array, common_values = {})
            array.map do |values|
              from_hash(values.merge(common_values))
            end if array
          end

          def self.from_hash(hash)
            return nil unless hash
            # in ruby 1.8, #members is an array of strings
            # in ruby 1.9, #members is an array of symbols
            members = new.members.map {|m| m.to_sym}
            values = members.map{|a| hash.has_key?(a) ? hash[a] : hash[a.to_s] }
            new(*values)
          end

        end
      end

      def api_get(uri, options = {})
        api.request(uri, options.merge(:method => :get))
      end

    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
engineyard-1.4.29 lib/engineyard/model/api_struct.rb
engineyard-1.4.28 lib/engineyard/model/api_struct.rb
engineyard-1.4.27 lib/engineyard/model/api_struct.rb
engineyard-1.4.24 lib/engineyard/model/api_struct.rb
engineyard-1.4.23 lib/engineyard/model/api_struct.rb
engineyard-1.4.22 lib/engineyard/model/api_struct.rb
engineyard-1.4.21 lib/engineyard/model/api_struct.rb
engineyard-1.4.20 lib/engineyard/model/api_struct.rb
engineyard-1.4.19 lib/engineyard/model/api_struct.rb
engineyard-1.4.18 lib/engineyard/model/api_struct.rb
engineyard-1.4.17 lib/engineyard/model/api_struct.rb
engineyard-1.4.16 lib/engineyard/model/api_struct.rb
engineyard-1.4.15 lib/engineyard/model/api_struct.rb
engineyard-1.4.14 lib/engineyard/model/api_struct.rb
engineyard-1.4.13 lib/engineyard/model/api_struct.rb
engineyard-1.4.11 lib/engineyard/model/api_struct.rb
engineyard-1.4.10 lib/engineyard/model/api_struct.rb
engineyard-1.4.9 lib/engineyard/model/api_struct.rb
engineyard-1.4.8 lib/engineyard/model/api_struct.rb
engineyard-1.4.7 lib/engineyard/model/api_struct.rb