Sha256: fe338972a42931df1542d7524b92b5d9e5c4349dc26bbf4c612eb35ef1bacbd9

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 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

  def self.default_injector=(injector)
    JSObjection.setDefaultInjector injector
  end

  def self.default_injector
    JSObjection.defaultInjector
  end

  module Initializer
    def objectionInitializer
      @_initializer
    end
  end

  module ClassMethods

    def compose_with(*args)
      @_type_mappings = {}
      properties = []
      args.each do |arg|
        if arg.is_a? Hash
          arg.each do |k,v|
            @_type_mappings[k.to_s] = v
            attr_accessor k
            properties << k
          end
        else
          prop = arg.split("/").last
          attr_accessor prop
          @_type_mappings[prop] = arg.to_s
          properties << prop
        end
      end
      @_dependencies = NSSet.setWithArray(properties.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
      @_type_mappings ||= {}
      if self.superclass.respondsToSelector :objectionTypeMappings
        @_type_mappings.merge self.superclass.objectionTypeMappings
      else
        @_type_mappings
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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