creates instance methods out of the associated resources from links
332945
protected function get_associated_resources($client,$links,Set &$associations=null) {

		$rels = [];
		foreach($links as $l) {
			if(array_key_exists($l->rel,$rels)) {
				$rels[$l->rel][] = $l->href;
			} else {
				$rels[$l->rel] = [$l->href];
			}
		}

		foreach($rels as $rel => $hrefs) {

			if(!is_null($associations)) {
				$associations[] = $rel;
			}

			$that = &$this;

			$this->methods->$rel = function($params=null) use (&$that,&$client,$rel,$hrefs) {

				if(count($hrefs) == 1) {

					if(Helper::has_id($params) || Helper::is_singular($rel)) {
						// user wants a single resource


						// calling data() you don't want a resource object back
						if($rel == "data") {
							return new ResourceDetail($hrefs[0],$params);
						}

						if(Helper::is_singular($rel)) {
							$resource_type = Helper::get_resource_type($hrefs[0],-2);
						} else {
							$resource_type = Helper::get_resource_type($hrefs[0],-1);
						}

						$path = Helper::add_id_and_params_to_path($hrefs[0],$params);

						Helper::get_resource_type($hrefs[0],-1);
						return Resource::Process($client,$resource_type,$path);

					} else {
						$resource_type = Helper::get_resource_type($hrefs[0],-1);
						$path = Helper::add_id_and_params_to_path($hrefs[0],$params);
						return new Resources($client,$resource_type,$path);
					}

				} else {
					$resources = [];
					if(Helper::has_id($params) || Helper::is_singular($rel)) {
						foreach($hrefs as $href) {
							// user wants a single resource. Doing show, update, delete, etc
							if(Helper::is_singular($rel)) {
								$resource_type = Helper::get_resource_type($href,-2);
							} else {
								$resource_type = Helper::get_resource_type($href,-1);
							}
							$path = Helper::add_id_and_params_to_path($href,$params);
							$resources[] = Resource::process($client,$resource_type,$path);
						}
					} else {
						foreach($hrefs as $href) {
							$resource_type = Helper::get_resource_type($href,-1);
							$path = Helper::add_id_and_params_to_path($href,$params);
							$resources[] = new Resources($client,$resource_type,$path);
						}
					}
					return $resources;
				}
			};
		}
	}
63368
private Links createLinksFrom(Object parseResult, LinkRelation rel) {

		if (JSONArray.class.isInstance(parseResult)) {

			JSONArray jsonArray = (JSONArray) parseResult;

			return jsonArray.stream() //
					.flatMap(it -> JSONArray.class.isInstance(it) ? ((JSONArray) it).stream() : Stream.of(it)) //
					.map(it -> extractLink(it, rel)) //
					.collect(Collectors.collectingAndThen(Collectors.toList(), Links::of));
		}

		return Links.of(Map.class.isInstance(parseResult) //
				? extractLink(parseResult, rel) //
				: new Link(parseResult.toString(), rel));
	}
469228
def dir_instance(inst):
    
    # Skip instance attributes; __slots__ is automatically defined, and
    # descriptors are used to define attributes. Instead, go straight to class
    # attributes (including methods).
    for name, value in vars_class(type(inst)).items():
        if isinstance(value, ObjectMethod):
            if value.has_instancemethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        elif isinstance(value, (classmethod, staticmethod)):
            pass  # Hide this; not interesting here.
        else:
            yield name
214829
function() {
  var coll = Object.create(Array.prototype);
  coll = (Array.apply(coll, arguments) || coll);

  LinkCollection.injectClassMethods(coll);
  return (coll);
}
1357337
def _closure_createlink(self):
        """"""
        linkparents = self._closure_model.objects.filter(
            child__pk=self._closure_parent_pk
        ).values("parent", "depth")
        linkchildren = self._closure_model.objects.filter(
            parent__pk=self.pk
        ).values("child", "depth")
        newlinks = [self._closure_model(
            parent_id=p['parent'],
            child_id=c['child'],
            depth=p['depth']+c['depth']+1
        ) for p in linkparents for c in linkchildren]
        self._closure_model.objects.bulk_create(newlinks)
505927
def build_json_resource_obj(cls, fields, resource, resource_instance, resource_name,
                                force_type_resolution=False):
        
        # Determine type from the instance if the underlying model is polymorphic
        if force_type_resolution:
            resource_name = utils.get_resource_type_from_instance(resource_instance)
        resource_data = [
            ('type', resource_name),
            ('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
            ('attributes', cls.extract_attributes(fields, resource)),
        ]
        relationships = cls.extract_relationships(fields, resource, resource_instance)
        if relationships:
            resource_data.append(('relationships', relationships))
        # Add 'self' link if field is present and valid
        if api_settings.URL_FIELD_NAME in resource and \
                isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
            resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
        return OrderedDict(resource_data)
809244
def generate
      instance_eval(&callbacks[:setup])
      if options.only_recursion_depth.present?
        depth = options.only_recursion_depth.to_i
        options[:only].dup.each do |class_name|
          options[:only]+= recurse_into_relationships(@domain.entity_by_name(class_name), depth)
        end
        options[:only].uniq!
      end

      filtered_entities.each do |entity|
        instance_exec entity, filtered_attributes(entity), &callbacks[:each_entity]
      end

      filtered_specializations.each do |specialization|
        instance_exec specialization, &callbacks[:each_specialization]
      end

      filtered_relationships.each do |relationship|
        instance_exec relationship, &callbacks[:each_relationship]
      end
    end
623703
function resourceToJsonObject (resource) {
    var result = {};

    for (var prop in resource) {

      if (prop === '_links') {
        if (Object.keys(resource._links).length > 0) {
          // Note: we need to copy data to remove "rel" property without corrupting original Link object
          result._links = Object.keys(resource._links).reduce(function (links, rel) {
            if (Array.isArray(resource._links[rel])) {
              links[rel] = new Array()
              for (var i=0; i < resource._links[rel].length; i++)
                links[rel].push(resource._links[rel][i].toJSON())
            } else {
              var link = resource._links[rel].toJSON();
              links[rel] = link;
              delete link.rel;
            }
            return links;
          }, {});
        }

      } else if (prop === '_embedded') {
        if (Object.keys(resource._embedded).length > 0) {
          // Note that we do not reformat _embedded
          // which means we voluntarily DO NOT RESPECT the following constraint:
          // > Relations with one corresponding Resource/Link have a single object
          // > value, relations with multiple corresponding HAL elements have an
          // > array of objects as their value.
          // Come on, resource one is *really* dumb.
          result._embedded = {};
          for (var rel in resource._embedded) {
            result._embedded[rel] = resource._embedded[rel].map(resourceToJsonObject);
          }
        }

      } else if (resource.hasOwnProperty(prop)) {
        result[prop] = resource[prop];
      }
    }

    return result;
  }
376678
def instantiate(params)
      instance = Instance.new( *interpolate(params), @parent )
      instance.apply_resource_type
      instance
    end
1058923
def bind(self, instance, auto=False):
        
        methods = [
            (m, cls.__dict__[m])
            for cls in inspect.getmro(type(instance))
            for m in cls.__dict__ if inspect.isfunction(cls.__dict__[m])
            ]

        try:
            deps_of_endpoints = [(method_ptr, self.entrypoint_deps(method_ptr))
                                 for (method_name, method_ptr) in methods]

            for (method_ptr, method_deps) in deps_of_endpoints:
                if len(method_deps) > 0:
                    method_ptr(instance, **method_deps)
        except KeyError:
            pass

        if auto and instance not in self.current_scope.get_auto_bind_list():
            self.current_scope.auto_bind(instance)

        return instance
204420
private void injectStructMethods(MethodDefinition read, LocalVariableDefinition instance, Map<Short, LocalVariableDefinition> structData)
    {
        for (ThriftMethodInjection methodInjection : metadata.getMethodInjections()) {
            injectMethod(read, methodInjection, instance, structData);
        }
    }
280914
def instance_writers
      _attrs.keys.map { |m| "#{m}=".to_sym }.select { |m| method_defined?(m) }
    end
346472
def instance(self_or_cls,**params):
        

        if isinstance (self_or_cls,ParameterizedMetaclass):
            cls = self_or_cls
        else:
            p = params
            params = dict(self_or_cls.get_param_values())
            params.update(p)
            params.pop('name')
            cls = self_or_cls.__class__

        inst=Parameterized.__new__(cls)
        Parameterized.__init__(inst,**params)
        if 'name' in params:  inst.__name__ = params['name']
        else:                 inst.__name__ = self_or_cls.name
        return inst
1202372
function extractAndUpdateResources(data, links, rootResource, resource) {
      var resources = [];

      var selfHref = ((data._links || {}).self || {}).href;
      if (!selfHref) {
        throw new Error('Self link href expected but not found');
      }

      // Extract links
      angular.extend(links, data._links);
      delete data._links;

      // Extract and update embedded resources
      Object.keys(data._embedded || {}).forEach(function (rel) {
        var embeds = data._embedded[rel];

        // Add link to embedded resource if missing
        if (!(rel in links)) {
          links[rel] = forArray(embeds, function (embedded) {
            return {href: embedded._links.self.href};
          });
        }
        // Recurse into embedded resource
        forArray(embeds, function (embedded) {
          resources = resources.concat(extractAndUpdateResources(embedded, {}, rootResource, null));
        });
      });
      delete data._embedded;

      // Update resource
      if (!resource) resource = rootResource.$context.get(links.self.href, rootResource.constructor);
      Resource.prototype.$update.call(resource, data, links);
      resources.push(resource);

      return resources;
    }
3341
def create_memoized_method
      name, method, freezer = @method_name, @original_method, @freezer
      @descendant.module_eval do
        define_method(name) do |&block|
          fail BlockNotAllowedError.new(self.class, name) if block
          memoized_method_cache.fetch(name) do
            freezer.call(method.bind(self).call)
          end
        end
      end
    end
1145489
def resource_from_params(type, *resources)
      res = resources.clone

      options = res.extract_options!
      r = res.first

      type == :resource ? ActionDispatch::Routing::Mapper::SingletonResource.new(r, options.dup) : ActionDispatch::Routing::Mapper::Resource.new(r, options.dup)
    end
1243489
def _build_and_attach_node(endpoint_class, method_name=nil)
      # Create the new endpoint
      endpoint_instance = endpoint_class.new(@requester, method_name, self)
      # Attach the endpoint as an instance variable and method
      method_name ||= endpoint_class.name.demodulize.underscore
      self.instance_variable_set("@#{method_name}", endpoint_instance)
      self.define_singleton_method(method_name.to_s) { endpoint_instance }
      endpoint_instance
    end