# all files / features/ComponentEditor/Models/ MethodModel.js

100% Statements 19/19
100% Branches 2/2
100% Functions 9/9
100% Lines 19/19

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60

    1

    1

    1

    1

    58
    40

    40

    7

    14

    1

    93

    40
    19

    58

    1
    40
    14

    1

    58

     'use strict';

    // Utilities:
    var _ = require('lodash');

    // Module:
    var ComponentEditor = require('../ComponentEditor');

    // Dependencies:
    require('./ArgumentModel');

    var createMethodModelConstructor = function (
        ArgumentModel
    ) {
        var MethodModel = function MethodModel (interaction, method) {
            this.arguments = getArguments.call(this, method);

            Object.defineProperties(this, {
                interaction: {
                    get: function () {
                        return interaction;
                    }
                },
                name: {
                    get: function () {
                        return method.name;
                    }
                },
                description: {
                    get: function () {
                        return method.description;
                    }
                },
                returns: {
                    get: function () {
                        return method.returns;
                    }
                }
            });

            if (this.returns) {
                this[this.returns] = method[this.returns];
            }
        };

        return MethodModel;

        function getArguments (method) {
            return _.map(method.arguments, function (argument) {
                return new ArgumentModel(this, argument);
            }, this);
        }
    };

    ComponentEditor.factory('MethodModel', function (
        ArgumentModel
    ) {
        return createMethodModelConstructor(ArgumentModel);
    });