Sha256: 8752bf84aefe2dfb14d3e4d2b92042fe8e39b8c8978dbb3ed9433dc5132dc558

Contents?: true

Size: 1.74 KB

Versions: 8

Compression:

Stored size: 1.74 KB

Contents

class RFlow
  module Components
    module File
      module Extensions
        # Need to be careful when extending to not clobber data already in data_object
        module FileExtension
          def self.extended(base_data)
            base_data.data_object ||= {
              'path' => '/', 'size' => 0, 'content' => '',
              'creation_timestamp' => nil, 'modification_timestamp' => nil, 'access_timestamp' => nil
            }
          end

          # Default/string accessors
          ['path', 'content'].each do |name|
            define_method name do |*args|
              data_object[name]
            end
            define_method :"#{name}=" do |*args|
              data_object[name] = args.first
            end
          end

          # Integer Accessors
          ['size'].each do |name|
            define_method name do |*args|
              data_object[name]
            end
            define_method :"#{name}=" do |*args|
              data_object[name] = args.first.to_i
            end
          end

          # Timestamp Accessors.  Note, the precision of the
          # XMLTimestamp is set to 9 digits, meaning that the time you
          # put in might be slightly different from the time you read
          # out.
          ['creation_timestamp', 'modification_timestamp', 'access_timestamp'].each do |name|
            define_method name do |*args|
              data_object[name] ? Time.xmlschema(data_object[name]) : nil
            end
            define_method :"#{name}=" do |*args|
              if args.first.is_a? Time
                data_object[name] = args.first.xmlschema(9)
              else
                data_object[name] = args.first
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rflow-components-file-1.2.0 lib/rflow/components/file/extensions.rb
rflow-components-file-1.1.1 lib/rflow/components/file/extensions.rb
rflow-components-file-1.1.0 lib/rflow/components/file/extensions.rb
rflow-components-file-1.0.1 lib/rflow/components/file/extensions.rb
rflow-components-file-1.0.0 lib/rflow/components/file/extensions.rb
rflow-components-file-1.0.0a4 lib/rflow/components/file/extensions.rb
rflow-components-file-1.0.0a3 lib/rflow/components/file/extensions.rb
rflow-components-file-1.0.0a2 lib/rflow/components/file/extensions.rb