Class: GitHub::Helper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/github_api/base.rb

Overview

Singleton class, that is used globally

Class Method Summary collapse

Class Method Details

.build_from_yaml(yaml) ⇒ GitHub::User, Array

Deprecated.

Nothing uses it, but may come handy later

Recognizing objects retrieved from GitHub, creating new and assigning parameters from YAML

Objects

  • GitHub::User - recognition by key ‘user’

More to be added soon

Parameters:

  • yaml (String)

    a YAML content to be parsed

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/github_api/base.rb', line 80

def self.build_from_yaml(yaml)
  yaml = YAML::load yaml
  object = case
    when yaml.has_key?('user') then [GitHub::User, 'user']
    when yaml.has_key?('users') then [[GitHub::User], 'users']
  end
  if object.first.class == Array
    objects = []
    yaml[object[1]].each do |single_yaml|
      o = object.first.first.new
      o.build single_yaml
      objects << o
    end
    objects
  else
    object[0] = object.first.new
    object.first.build yaml[object[1]]
    object.first
  end
end