Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gitmodel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Gem::Specification.new do |s|
of all changes.
DESC

s.add_dependency 'activemodel', '~> 3.0.1'
s.add_dependency 'activesupport', '~> 3.0.1'
s.add_dependency 'activemodel', '>= 3.0.1'
s.add_dependency 'activesupport', '>= 3.0.1'
s.add_dependency 'dalli'
s.add_dependency 'grit', '>= 2.3.0'
s.add_dependency 'lockfile', '>= 1.4.3'
Expand Down
23 changes: 11 additions & 12 deletions lib/gitmodel/persistable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ def self.included(base)


def initialize(args = {})
_run_initialize_callbacks do
@new_record = true
self.attributes = {}
self.blobs = {}
args.each do |k,v|
self.send("#{k}=".to_sym, v)
end
@new_record = true
self.attributes = {}
self.blobs = {}
args.each do |k,v|
self.send("#{k}=".to_sym, v)
end
run_callbacks :initialize
end

def to_model
Expand Down Expand Up @@ -108,7 +107,7 @@ def persisted?
# :commit_message
# Returns false if validations failed, otherwise returns the SHA of the commit
def save(options = {})
_run_save_callbacks do
run_callbacks(:save) do
raise GitModel::NullId unless self.id

if new_record?
Expand Down Expand Up @@ -169,7 +168,7 @@ def to_s
private

def load(dir, branch)
_run_find_callbacks do
run_callbacks(:find) do
# remove dangerous ".."
# todo find a better way to ensure path is safe
dir.gsub!(/\.\./, '')
Expand Down Expand Up @@ -333,7 +332,7 @@ def find_all(conditions = {})

def all_values_for_attr(attr)
attr_index = index.attr_index(attr.to_s)
values = attr_index ? attr_index.keys : []
attr_index ? attr_index.keys : []
end

def create(args)
Expand All @@ -360,7 +359,7 @@ def delete(id, options = {})
GitModel.logger.debug "Deleting #{name} with id: #{id}"
path = File.join(db_subdir, id)
transaction = options.delete(:transaction) || GitModel::Transaction.new(options)
result = transaction.execute do |t|
transaction.execute do |t|
branch = t.branch || options[:branch] || GitModel.default_branch
delete_tree(path, t.index, branch, options)
end
Expand All @@ -369,7 +368,7 @@ def delete(id, options = {})
def delete_all(options = {})
GitModel.logger.debug "Deleting all #{name.pluralize}"
transaction = options.delete(:transaction) || GitModel::Transaction.new(options)
result = transaction.execute do |t|
transaction.execute do |t|
branch = t.branch || options[:branch] || GitModel.default_branch
delete_tree(db_subdir, t.index, branch, options)
end
Expand Down