From 65615521832c557f0f337003674ba1d45009dea7 Mon Sep 17 00:00:00 2001 From: Bohuslav Kabrda <bkabrda@redhat.com> Date: Wed, 29 Feb 2012 10:02:25 +0100 Subject: [PATCH] Unbundle files from activesupport --- lib/dbus.rb | 1 - lib/dbus/core_ext/class/attribute.rb | 91 --------------------------- lib/dbus/core_ext/kernel/singleton_class.rb | 14 ---- lib/dbus/core_ext/module/remove_method.rb | 12 ---- lib/dbus/export.rb | 22 ++++++- 5 files changed, 21 insertions(+), 119 deletions(-) delete mode 100644 lib/dbus/core_ext/class/attribute.rb delete mode 100644 lib/dbus/core_ext/kernel/singleton_class.rb delete mode 100644 lib/dbus/core_ext/module/remove_method.rb diff --git a/lib/dbus.rb b/lib/dbus.rb index bbb1b97..e49df8c 100644 --- a/lib/dbus.rb +++ b/lib/dbus.rb @@ -8,7 +8,6 @@ # License, version 2.1 as published by the Free Software Foundation. # See the file "COPYING" for the exact licensing terms. -require 'dbus/core_ext/class/attribute' require 'dbus/type' require 'dbus/introspect' require 'dbus/error' diff --git a/lib/dbus/core_ext/class/attribute.rb b/lib/dbus/core_ext/class/attribute.rb deleted file mode 100644 index 3b9caa3..0000000 --- a/lib/dbus/core_ext/class/attribute.rb +++ /dev/null @@ -1,91 +0,0 @@ -# copied from activesupport/core_ext from Rails, MIT license -require 'dbus/core_ext/kernel/singleton_class' -require 'dbus/core_ext/module/remove_method' - -class Class - # Declare a class-level attribute whose value is inheritable by subclasses. - # Subclasses can change their own value and it will not impact parent class. - # - # class Base - # class_attribute :setting - # end - # - # class Subclass < Base - # end - # - # Base.setting = true - # Subclass.setting # => true - # Subclass.setting = false - # Subclass.setting # => false - # Base.setting # => true - # - # In the above case as long as Subclass does not assign a value to setting - # by performing <tt>Subclass.setting = _something_ </tt>, <tt>Subclass.setting</tt> - # would read value assigned to parent class. Once Subclass assigns a value then - # the value assigned by Subclass would be returned. - # - # This matches normal Ruby method inheritance: think of writing an attribute - # on a subclass as overriding the reader method. However, you need to be aware - # when using +class_attribute+ with mutable structures as +Array+ or +Hash+. - # In such cases, you don't want to do changes in places but use setters: - # - # Base.setting = [] - # Base.setting # => [] - # Subclass.setting # => [] - # - # # Appending in child changes both parent and child because it is the same object: - # Subclass.setting << :foo - # Base.setting # => [:foo] - # Subclass.setting # => [:foo] - # - # # Use setters to not propagate changes: - # Base.setting = [] - # Subclass.setting += [:foo] - # Base.setting # => [] - # Subclass.setting # => [:foo] - # - # For convenience, a query method is defined as well: - # - # Subclass.setting? # => false - # - # Instances may overwrite the class value in the same way: - # - # Base.setting = true - # object = Base.new - # object.setting # => true - # object.setting = false - # object.setting # => false - # Base.setting # => true - # - # To opt out of the instance writer method, pass :instance_writer => false. - # - # object.setting = false # => NoMethodError - def class_attribute(*attrs) - instance_writer = !attrs.last.is_a?(Hash) || attrs.pop[:instance_writer] - - attrs.each do |name| - class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def self.#{name}() nil end - def self.#{name}?() !!#{name} end - - def self.#{name}=(val) - singleton_class.class_eval do - remove_possible_method(:#{name}) - define_method(:#{name}) { val } - end - val - end - - def #{name} - defined?(@#{name}) ? @#{name} : singleton_class.#{name} - end - - def #{name}? - !!#{name} - end - RUBY - - attr_writer name if instance_writer - end - end -end diff --git a/lib/dbus/core_ext/kernel/singleton_class.rb b/lib/dbus/core_ext/kernel/singleton_class.rb deleted file mode 100644 index 80cc00e..0000000 --- a/lib/dbus/core_ext/kernel/singleton_class.rb +++ /dev/null @@ -1,14 +0,0 @@ -# copied from activesupport/core_ext from Rails, MIT license -module Kernel - # Returns the object's singleton class. - def singleton_class - class << self - self - end - end unless respond_to?(:singleton_class) # exists in 1.9.2 - - # class_eval on an object acts like singleton_class.class_eval. - def class_eval(*args, &block) - singleton_class.class_eval(*args, &block) - end -end diff --git a/lib/dbus/core_ext/module/remove_method.rb b/lib/dbus/core_ext/module/remove_method.rb deleted file mode 100644 index ef6a9ec..0000000 --- a/lib/dbus/core_ext/module/remove_method.rb +++ /dev/null @@ -1,12 +0,0 @@ -# copied from activesupport/core_ext from Rails, MIT license -class Module - def remove_possible_method(method) - remove_method(method) - rescue NameError - end - - def redefine_method(method, &block) - remove_possible_method(method) - define_method(method, &block) - end -end diff --git a/lib/dbus/export.rb b/lib/dbus/export.rb index cb79d26..4490e3b 100644 --- a/lib/dbus/export.rb +++ b/lib/dbus/export.rb @@ -20,7 +20,7 @@ module DBus # The path of the object. attr_reader :path # The interfaces that the object supports. Hash: String => Interface - class_attribute :intfs + @@intfs_hash = {DBus::Object => nil} # The service that the object is exported by. attr_writer :service @@ -34,6 +34,26 @@ module DBus @service = nil end + def self.intfs + if self.equal? DBus::Object + @@intfs_hash[DBus::Object] + else + @@intfs_hash[self] || self.superclass.intfs + end + end + + def self.intfs= param + @@intfs_hash[self] = param + end + + def intfs + self.class.intfs + end + + def intfs= param + self.class.intfs = param + end + # State that the object implements the given _intf_. def implements(intf) # use a setter -- 1.7.9.1