Sha256: fa7713d21508ddca07a43c2a6bf3e9352a5ff09179de6218b35326975000c6ef

Contents?: true

Size: 784 Bytes

Versions: 9

Compression:

Stored size: 784 Bytes

Contents

module Celluloid
  # Properties define inheritable attributes of classes, somewhat similar to
  # Rails cattr_*/mattr_* or class_attribute
  module Properties
    def property(name, opts = {})
      default   = opts.fetch(:default, nil)
      multi     = opts.fetch(:multi, false)
      ivar_name = "@#{name}".to_sym

      ancestors.first.send(:define_singleton_method, name) do |value = nil, *extra|
        if value
          value = value ? [value, *send(name), *extra].uniq : [] if multi
          instance_variable_set(ivar_name, value)
        elsif instance_variables.include?(ivar_name)
          instance_variable_get(ivar_name)
        elsif superclass.respond_to? name
          superclass.send(name)
        else
          default
        end
      end
    end
  end
end

Version data entries

9 entries across 7 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/lib/celluloid/properties.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/properties.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/properties.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/properties.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/lib/celluloid/properties.rb
celluloid-0.16.0 lib/celluloid/properties.rb
celluloid-0.16.0.pre3 lib/celluloid/properties.rb
celluloid-0.16.0.pre2 lib/celluloid/properties.rb
celluloid-0.16.0.pre lib/celluloid/properties.rb