Sha256: 8ba7c1eaf5ebba231d92f33a3e3ad6e96f1bea196f1cc59af40123e9aa903c9a

Contents?: true

Size: 1017 Bytes

Versions: 14

Compression:

Stored size: 1017 Bytes

Contents

class OmRecord 
  extend ActiveSupport::Concern

  included do
    ##
    # This stuff is so we can store and retrieve data off the filesystem. Don't worry about it.
    extend ActiveModel::Naming
    include ActiveModel::Conversion

    attr_writer :file
  
    attr_accessor :name
    attr_reader   :errors
  end

  def initialize options={}

    @errors = ActiveModel::Errors.new(self)

    self.ng_xml = self.class.xml_template

    options.each do |k,v|
      send("#{k}=", v)
    end
  end

  def file
    @file ||= "db/datasets/#{Time.now.to_i}"
  end

  def id
    File.basename(file)
  end

  def save
    File.open(file, 'w') { |f| f.puts ng_xml.to_s }
  end

  def persisted?
    File.exists? file
  end

  class ClassMethods
    def all
      Dir.glob('db/datasets/*').map do |f|
        Dataset.from_file(f)
      end
    end

    def find id
      Dataset.from_file("db/datasets/#{id}")
    end

    def from_file f
      d = Dataset.from_xml(File.read(f))

      d.file = f

      d
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hydra-tutorial-0.2.1 old_tutorial/templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.2.0 old_tutorial/templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.1.3 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.1.2 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.1.0 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.9 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.8 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.7 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.6 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.5 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.4 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.3 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.2 templates/building_a_basic_rails_app/om_record.rb
hydra-tutorial-0.0.1 templates/building_a_basic_rails_app/om_record.rb