Sha256: 5dda1c9b23f29e0167486118cf3144209367e86e530d3839f49dc88c4e6a78ab

Contents?: true

Size: 678 Bytes

Versions: 25

Compression:

Stored size: 678 Bytes

Contents

require 'yaml'
require 'json'

module Vx
  module Builder
    class Source

      module Serializable

        def self.included(base)
          base.extend ClassMethods
        end

        def to_yaml
          YAML.dump(attributes)
        end

        def to_hash
          attributes
        end

        module ClassMethods

          def from_file(file)
            if File.readable? file
              from_yaml File.read(file)
            end
          end

          def from_yaml(yaml)
            from_attributes YAML.load(yaml)
          end

          def from_attributes(attrs)
            Source.new attrs
          end

        end

      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
vx-builder-0.0.27 lib/vx/builder/source/serializable.rb
vx-builder-0.0.26 lib/vx/builder/source/serializable.rb
vx-builder-0.0.25 lib/vx/builder/source/serializable.rb
vx-builder-0.0.24 lib/vx/builder/source/serializable.rb
vx-builder-0.0.23 lib/vx/builder/source/serializable.rb
vx-builder-0.0.22 lib/vx/builder/source/serializable.rb
vx-builder-0.0.21 lib/vx/builder/source/serializable.rb
vx-builder-0.0.20 lib/vx/builder/source/serializable.rb
vx-builder-0.0.19 lib/vx/builder/source/serializable.rb
vx-builder-0.0.18 lib/vx/builder/source/serializable.rb
vx-builder-0.0.16 lib/vx/builder/source/serializable.rb
vx-builder-0.0.15 lib/vx/builder/source/serializable.rb
vx-builder-0.0.14 lib/vx/builder/source/serializable.rb
vx-builder-0.0.13 lib/vx/builder/source/serializable.rb
vx-builder-0.0.12 lib/vx/builder/source/serializable.rb
vx-builder-0.0.11 lib/vx/builder/source/serializable.rb
vx-builder-0.0.10 lib/vx/builder/source/serializable.rb
vx-builder-0.0.9 lib/vx/builder/source/serializable.rb
vx-builder-0.0.8 lib/vx/builder/source/serializable.rb
vx-builder-0.0.7 lib/vx/builder/source/serializable.rb