Sha256: ec532ec0faf35a25b787120ca4435f1e077466f8ba7cb19c07de30b1bb31425e

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom'))
module Fathom
  module Properties
    
    def self.included(base)
      base.send(:extend, ClassMethods)
    end
    
    module ClassMethods
      
      def properties
        @properties ||= []
      end
      
      def property(name, opts={})
        self.properties << name_sym(name)
      end
      
      def define_property_states
        return true if @property_states_defined
        self.properties.each do |state_method_name|
          unless self.instance_methods.include?(state_method_name.to_s)
            define_method(state_method_name) do
              states[state_method_name]
            end
          end
          
          state_method_writer = "#{state_method_name}=".to_sym
          unless self.instance_methods.include?(state_method_writer.to_s)
            define_method(state_method_writer) do |value|
              states[state_method_name] = value
            end
          end
        end
        
        @property_states_defined = true
      end

      protected
        def name_sym(name)
          name.to_s.downcase.gsub(/\s+/, '_').to_sym
        end
        
    end
  end
end


Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fathom-0.3.7 lib/fathom/agent/properties.rb
fathom-0.3.6 lib/fathom/agent/properties.rb
fathom-0.3.4 lib/fathom/agent/properties.rb
fathom-0.3.3 lib/fathom/agent/properties.rb
fathom-0.3.2 lib/fathom/agent/properties.rb
fathom-0.3.1 lib/fathom/agent/properties.rb
fathom-0.3.0 lib/fathom/agent/properties.rb
fathom-0.2.3 lib/fathom/agent/properties.rb
fathom-0.2.2 lib/fathom/agent/properties.rb
fathom-0.2.1 lib/fathom/agent/properties.rb
fathom-0.2.0 lib/fathom/agent/properties.rb