Sha256: d2a90a175d9929f63070d30173d104f56fbaaf25cb7a1341d8b61204966cbf33

Contents?: true

Size: 1.63 KB

Versions: 20

Compression:

Stored size: 1.63 KB

Contents

module Resourcelogic # :nodoc:
  module Accessors # :nodoc:
    private
      def block_accessor(*accessors)
        accessors.each do |block_accessor|
          class_eval <<-"end_eval", __FILE__, __LINE__

            def #{block_accessor}(*args, &block)
              unless args.empty? && block.nil?
                args.push block if block_given?
                @#{block_accessor} = [args].flatten
              end
              
              @#{block_accessor}
            end

          end_eval
        end
      end
      
      def scoping_reader(*accessor_names)
        accessor_names.each do |accessor_name|        
          class_eval <<-"end_eval", __FILE__, __LINE__
            def #{accessor_name}(&block)
              @#{accessor_name}.instance_eval &block if block_given?
              @#{accessor_name}
            end
          end_eval
        end
      end
      
      def class_scoping_reader(accessor_name, start_value)
        write_inheritable_attribute accessor_name, start_value
        
        class_eval <<-"end_eval", __FILE__, __LINE__
          def self.#{accessor_name}(context = :root, &block)
            read_inheritable_attribute(:#{accessor_name}).instance_eval(&block) if block_given?
            read_inheritable_attribute(:#{accessor_name})
          end
        end_eval
      end
      
      def reader_writer(accessor_name)
        class_eval <<-"end_eval", __FILE__, __LINE__
          def #{accessor_name}(*args, &block)
            args << block unless block.nil?
            @#{accessor_name} = args.first unless args.empty?
            @#{accessor_name}
          end
        end_eval
      end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
binarylogic-resourcelogic-0.0.11 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.0.12 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.0 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.1 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.2 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.3 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.4 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.5 lib/resourcelogic/accessors.rb
binarylogic-resourcelogic-0.12.6 lib/resourcelogic/accessors.rb
resourcelogic-0.12.6 lib/resourcelogic/accessors.rb
resourcelogic-0.12.5 lib/resourcelogic/accessors.rb
resourcelogic-0.12.3 lib/resourcelogic/accessors.rb
resourcelogic-0.12.4 lib/resourcelogic/accessors.rb
resourcelogic-0.0.11 lib/resourcelogic/accessors.rb
resourcelogic-0.0.12 lib/resourcelogic/accessors.rb
resourcelogic-0.12.0 lib/resourcelogic/accessors.rb
resourcelogic-0.12.1 lib/resourcelogic/accessors.rb
resourcelogic-0.12.2 lib/resourcelogic/accessors.rb
resourcelogic-0.11.0 lib/resourcelogic/accessors.rb
resourcelogic-0.10.0 lib/resourcelogic/accessors.rb