Sha256: c6468a8000e6963521637bf40ce356947a5e813cedc80d24de753e9bba8536dd

Contents?: true

Size: 813 Bytes

Versions: 6

Compression:

Stored size: 813 Bytes

Contents

module ActiveGit
  module Inflector

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

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

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

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

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

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_git-0.0.10 lib/active_git/inflector.rb
active_git-0.0.9 lib/active_git/inflector.rb
active_git-0.0.8 lib/active_git/inflector.rb
active_git-0.0.7 lib/active_git/inflector.rb
active_git-0.0.6 lib/active_git/inflector.rb
active_git-0.0.5 lib/active_git/inflector.rb