Sha256: b24b189f9659880d47b6ba3ebef5b9e3f7bb51baea5b4ef96671d24df1b49a91

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

module Objection
  module Compose
    def self.included(base) #:nodoc:
      base.send :extend, ClassMethods
    end

    module Initializer #:nodoc:
      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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
motion-objection-0.8.6 lib/motion-objection/compose.rb
motion-objection-0.8.5 lib/motion-objection/compose.rb
motion-objection-0.8.4 lib/motion-objection/compose.rb
motion-objection-0.8.3 lib/motion-objection/compose.rb
motion-objection-0.8.2 lib/motion-objection/compose.rb
motion-objection-0.8.1 lib/motion-objection/compose.rb
motion-objection-0.8 lib/motion-objection/compose.rb
motion-objection-0.7.2 lib/motion-objection/compose.rb
motion-objection-0.7.1 lib/motion-objection/compose.rb