Sha256: 482799d220595cb03d830a2c46f2dd389d6ab30d4d99acec17e7028407e43d53

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

moduleKeywords = ['included', 'extended']

class Joosy.Module
  @__namespace__: []

  @__className = (klass) ->
    unless Object.isFunction(klass)
      klass = klass.constructor

    if klass.name?
      klass.name
    else
      klass.toString().replace /^function ([a-zA-Z]+)\([\s\S]+/, '$1'

  @hasAncestor: (what, klass) ->
    unless what? && klass?
      return false

    [what, klass] = [what.prototype, klass.prototype]

    while what
      if what == klass
        return true
      what = what.constructor?.__super__

    false
    
  @merge: (destination, source, unsafe=true) ->
    for key, value of source
      if source.hasOwnProperty(key)
        if unsafe || !destination.hasOwnProperty(key)
          destination[key] = value
    destination

  @include: (object) ->
    unless object
      throw new Error 'include(object) requires obj'

    Object.each object, (key, value) =>
      if key not in moduleKeywords
        this::[key] = value

    object.included?.apply this
    null

  @extend: (object) ->
    unless object
      throw new Error 'extend(object) requires object'

    @merge this, object

    object.extended?.apply this
    null

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joosy-0.1.0.RC2 app/assets/javascripts/joosy/core/modules/module.js.coffee