Class: DataMapper::Adapters::GitAdapter

Inherits:
AbstractAdapter
  • Object
show all
Includes:
Helpers
Defined in:
lib/dm-git-adapter.rb,
lib/dm-git-adapter/adapter.rb

Constant Summary collapse

VERSION =
"0.0.0alpha0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#create_db!, #current_tree, #json_file, #last_c, #records_for, #write_records

Constructor Details

#initialize(name, options) ⇒ GitAdapter

Returns a new instance of GitAdapter


7
8
9
10
11
12
13
# File 'lib/dm-git-adapter/adapter.rb', line 7

def initialize(name, options)
  super

  @path = @options[:path] || '/tmp/dm-git-data'
  File.exists?(@path)? self : create_db!
  @repo = Grit::Repo.new(@path)
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs


3
4
5
# File 'lib/dm-git-adapter/adapter.rb', line 3

def attrs
  @attrs
end

#indexObject

Returns the value of attribute index


3
4
5
# File 'lib/dm-git-adapter/adapter.rb', line 3

def index
  @index
end

#pathObject

Returns the value of attribute path


3
4
5
# File 'lib/dm-git-adapter/adapter.rb', line 3

def path
  @path
end

Instance Method Details

#create(resources) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/dm-git-adapter/adapter.rb', line 15

def create(resources)
  resources.each do |resource|
    write_records(resources.first.model, resource.attributes) do |t|
      #initialize_serial(resource, t.attrs.size.succ)
      t.index.add(File.join(resource.class.storage_name.to_s, "attributes.json"), JSON.pretty_generate(resource.attributes))
    end
  end
end

#read(query) ⇒ Object


24
25
26
27
28
# File 'lib/dm-git-adapter/adapter.rb', line 24

def read(query)
  #object = records_for(query.model.storage_name.to_s)
  #puts object
  query.filter_records(records_for(query.model.storage_name).dup)
end