Module: ActiveGit::Inflector

Defined in:
lib/active_git/inflector.rb

Class Method Summary collapse

Class Method Details

.dirname(model, working_path = nil) ⇒ Object



8
9
10
# File 'lib/active_git/inflector.rb', line 8

def self.dirname(model, working_path=nil)
  "#{working_path || ActiveGit.configuration.working_path}/#{relative_dirname(model)}"
end

.filename(instance, working_path = nil) ⇒ Object



12
13
14
# File 'lib/active_git/inflector.rb', line 12

def self.filename(instance, working_path=nil)
  "#{dirname(instance.class, working_path || ActiveGit.configuration.working_path)}/#{instance.id}.json"
end

.model(filename, working_path = nil) ⇒ Object



20
21
22
# File 'lib/active_git/inflector.rb', line 20

def self.model(filename, working_path=nil)
  File.dirname(filename.gsub(working_path || ActiveGit.configuration.working_path, '')).classify.constantize
end

.model_id(filename) ⇒ Object



24
25
26
# File 'lib/active_git/inflector.rb', line 24

def self.model_id(filename)
  File.basename(filename, '.json')
end

.relative_dirname(model) ⇒ Object



4
5
6
# File 'lib/active_git/inflector.rb', line 4

def self.relative_dirname(model)
  model.model_name.underscore.pluralize
end

.relative_filename(instance) ⇒ Object



16
17
18
# File 'lib/active_git/inflector.rb', line 16

def self.relative_filename(instance)
  "#{relative_dirname(instance.class)}/#{instance.id}.json"
end