Sha256: 815d11608fc51ea0a3eead44a19390e07dad0306d4de987b6fc2e9d6e197ea76

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

module Objection

  def self.included(base)
    base.send :extend, ClassMethods
  end

  def self.injector(*modules)
    if modules.empty?
      JSObjection.createInjector
    elsif modules.size == 1
      JSObjection.createInjector modules.first
    else
      JSObjection.createInjectorWithModulesArray modules
    end
  end

  module Initializer
    def objectionInitializer
      @_initializer
    end
  end

  module ClassMethods

    def compose_with(*args)
      props = args.map { |x| x.split("/").last }
      props.each { |x| attr_accessor x }
      @_types_mappings = {}
      props.each_index { |i| @_types_mappings[props[i]] = args[i] }
      @_dependencies = NSSet.setWithArray(props.map(&:to_s))
    end

    def singleton
      JSObjection.registerClass self, scope: JSObjectionScopeSingleton 
    end

    def initializer(selector, *args)
      self.send :extend, Initializer 
      @_initializer = {
        "initializer" => selector,
        "arguments" => args
      }
    end

    protected 

    def objectionRequires
      @_dependencies ||= NSSet.set
      if self.superclass.respondsToSelector :objectionRequires
        set = NSMutableSet.setWithSet self.superclass.objectionRequires
        set.unionSet @_dependencies
        set
      else
        @_dependencies
      end
    end

    def objectionTypeMappings
      @_types_mappings ||= {}
      if self.superclass.respondsToSelector :objectionTypeMappings
        @_types_mappings.merge self.superclass.objectionTypeMappings
      else
        @_types_mappings
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-objection-0.5 lib/motion-objection/objection.rb