fieldmatter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "grit", "~>2.4"
4
+ gem "json", "~>1.6"
5
+
6
+ gem "ohm", "~>0.1.3"
7
+ gem "ohm-contrib", "~>0.1.2"
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ grit (2.4.1)
6
+ diff-lcs (~> 1.1)
7
+ mime-types (~> 1.15)
8
+ json (1.6.5)
9
+ mime-types (1.17.2)
10
+ nest (1.1.0)
11
+ redis (~> 2.1)
12
+ ohm (0.1.3)
13
+ nest (~> 1.0)
14
+ ohm-contrib (0.1.2)
15
+ ohm
16
+ redis (2.2.2)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ grit (~> 2.4)
23
+ json (~> 1.6)
24
+ ohm (~> 0.1.3)
25
+ ohm-contrib (~> 0.1.2)
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Extremely primitive vision for the project
2
+
3
+ I've decided to write a program that will start as a simple command line wrapper for git and capture the extended attributes of the files before the git commit. It stores them in a specific file or location(to be determined). This file, or files, is then committed along with the rest of the git commit. On the other end it can then be accessed directly through the repo itself to construct images of all the repo objects as files with their original extended attributes.
4
+
5
+ My main motivation in writing this comes from the desire to use extended attributes in my note/document/file management system. Initially I have a repo full of markdown files (.md) that I want to set specific attributes for and store those attributes as extended attributes. Tags, Author, Permissions, etc are the main things I'd like to preserve.
data/bin/fieldmatter ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ # bin/fieldmatter - fieldmatter Ruby Gem executeable for clientside fieldmatter syncing
3
+
4
+ #require 'fieldmatter' # eventually will only need gem name
5
+ require '/Users/fielding/work/fieldmatter/lib/fieldmatter.rb' # temporary for development of gem
6
+ require 'optparse'
7
+
8
+
9
+ maximum_line_length = 80
10
+
11
+
12
+ module Colorize
13
+ def purple ( text )
14
+ colorized_output = true
15
+ purple = "\e[35m"
16
+ reset_color = "\e[0m"
17
+
18
+ output = text
19
+ if colorized_output
20
+ output.insert(0, purple) # start purple color
21
+ output.insert(-1, reset_color) # reset color back to what it was
22
+ end
23
+ end
24
+ end
25
+
26
+ OptionParser.new do |op|
27
+ include Colorize
28
+ # set banner for help documentation
29
+ op.set_banner(purple("Usage:") + " fieldmatter [options]\n" \
30
+ + purple("Description:") + " Clientside utility for working with tags, extended attributes and openmeta data")
31
+ op.separator " "
32
+ op.separator(purple("Specific options:"))
33
+
34
+ op.on("--no-color", "Disable colorized output") do |color|
35
+ colorized_output = color
36
+ end
37
+
38
+ op.on_tail("-h", "--help", "Displays this help message") do
39
+ $stderr.puts op
40
+ exit 1
41
+ end
42
+
43
+ op.on_tail("--version", "Prints the version") do
44
+ puts FieldMatter::VERSION
45
+ exit
46
+ end
47
+ end.parse!
48
+
49
+
50
+ # taken from old fieldmatter.rb file, needs lots of cleanup, but for now it works
51
+
52
+ sm = FieldMatter::StrangeMatter.new('/Users/fielding/notes')
53
+ sm.update
54
+
55
+ ## might add update_repo( repo ) for StrangeMatter that combines the above in to one line
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fieldmatter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fieldmatter"
7
+ s.version = FieldMatter::VERSION
8
+ s.authors = ["Fielding Johnston"]
9
+ s.email = ["fielding@justfielding.com"]
10
+ s.homepage = 'https://github.com/justfielding/fieldMatter'
11
+ s.summary = "taxonomy with redis and extended attributes"
12
+ s.description = "Library used in the fieldnote personal content management system. I wrote this library to assist in accessing extended attributes from support operating systems and then transferring them, despite the git backend, to the fieldnote server. Once there they are stored in a redis database for further manipulation."
13
+
14
+ s.rubyforge_project = "fieldmatter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,9 @@
1
+ #!/Users/fielding/.rbenv/versions/1.9.2-p290/bin/ruby
2
+ # FieldMatter - git post-receive hook
3
+
4
+ require '/Users/fielding/work/fieldmatter/lib/fieldmatter.rb'
5
+
6
+ dm = FieldMatter::DarkMatter.new('/Users/fielding/notes')
7
+ dm.update
8
+
9
+ ## might add update_repo( repo ) for DarkMatter that combines the above in to one line
@@ -0,0 +1,9 @@
1
+ #!/Users/fielding/.rbenv/versions/1.9.2-p290/bin/ruby
2
+ # FieldMatter - git post-receive hook
3
+
4
+ require '/Users/fielding/work/fieldmatter/lib/fieldmatter.rb'
5
+
6
+ dm = FieldMatter::DarkMatter.new('/Users/fielding/notes')
7
+ dm.update
8
+
9
+ ## might add update_repo( repo ) for DarkMatter that combines the above in to one line
@@ -0,0 +1,38 @@
1
+ # FieldMatter::DarkMatter
2
+
3
+ # require
4
+ require 'ohm'
5
+ require 'ohm/contrib'
6
+ require 'JSON'
7
+ require 'grit'
8
+
9
+ class FieldMatter
10
+ class DarkMatter
11
+ attr_reader :repo, :repo_path, :what_matters
12
+
13
+ def initialize( repo_path )
14
+ @repo_path = repo_path
15
+ end
16
+
17
+ def repo
18
+ Grit::Repo.new(self.repo_path)
19
+ end
20
+
21
+ def what_matters
22
+ JSON.parse((self.repo.tree / 'fieldmatter.json').data)
23
+ end
24
+
25
+ def update
26
+ self.what_matters.each do | key, value |
27
+ if not FieldMatter::Note.find(filename: key).empty?
28
+ canon = Base64.encode64(key).chomp
29
+ id = Ohm.redis.smembers("FieldMatter::Note:filename:#{canon}").pop
30
+ note = FieldMatter::Note[id]
31
+ note.update(:tags => value['kMDItemOMUserTags'])
32
+ else
33
+ FieldMatter::Note.create(:filename => key, :tags => value['kMDItemOMUserTags'])
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ # FieldMatter:Note
2
+
3
+ # requires
4
+ require 'ohm'
5
+ require 'ohm/contrib'
6
+
7
+ class FieldMatter
8
+
9
+ class Note < Ohm::Model
10
+ include Ohm::Callbacks
11
+
12
+ attribute :filename
13
+ attribute :tags
14
+ index :tag
15
+ index :filename
16
+
17
+ def tag(tags = self.tags)
18
+ return tags
19
+ end
20
+
21
+ # I don't full understand callbacks, so this is fubar. Will try to fix soon
22
+ protected
23
+ def before_save
24
+ # tag(read_remote(:tags)).map(&Tag).each { |t| t.decr :total}
25
+ end
26
+
27
+ def after_save
28
+ #tag.map(&Tag).each { |t| t.incr :total}
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ # FieldMatter::StrangeMatter
2
+
3
+ # require
4
+
5
+ class FieldMatter
6
+ class StrangeMatter
7
+ attr_reader :repo, :repo_path, :tags_matter
8
+
9
+ def initialize ( repo_path )
10
+ @repo_path = repo_path
11
+ @tags_matter = Hash.new
12
+ end
13
+
14
+ def as_json ( object )
15
+ JSON.generate(object)
16
+ end
17
+
18
+ def update
19
+ changes = self.repo.status.changed # Determine files/objects in the git repo that have been flagged for update
20
+
21
+ changes.delete(".gitignore") # Any non-tagged/tag-important files that aren't ignored in .gitignore or info/exclude
22
+ changes.delete("fieldmatter.json") # are potential problems/waste of database space. This will delete them if they turn up.
23
+
24
+ changes.keys.each do |file| # for each file that has changed
25
+ self.mdluvin( file ) # show these files some mdluvin; aka get a list of extended attribute openmeta tags from mdls.
26
+ end
27
+
28
+ self.write_to_json
29
+ end
30
+
31
+ def repo
32
+ Grit::Repo.new(self.repo_path) # Grab repo object using Grit
33
+ end
34
+
35
+ def mdluvin ( file )
36
+ file_path = self.repo_path + '/' + file
37
+ tags = %x{mdls -name 'kMDItemOMUserTags' -raw "#{file_path}"|awk '/[^()]/ {print $NF}'|tr -d '\n'}.split(',')
38
+ puts "Updating tags associated with #{file}: #{tags}"
39
+ # Possibly temporary, might change the array/hash construction to different methods
40
+ @tags_matter.store(file, tags)
41
+ end
42
+
43
+ def what_matters
44
+ what_matters = Hash.new
45
+ @tags_matter.each do | filename, tags |
46
+ strange_matter = Hash['kMDItemOMUserTags' => tags]
47
+ what_matters.store(filename, strange_matter)
48
+ end
49
+
50
+ return what_matters
51
+ end
52
+
53
+ def write_to_json
54
+ json_matters = self.as_json( self.what_matters )
55
+ File.open("#{self.repo_path}/fieldmatter.json", "w") do |f|
56
+ f.write(json_matters)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,15 @@
1
+ # FieldMatter::Tag
2
+
3
+ # requires
4
+ require 'ohm'
5
+
6
+ class FieldMatter
7
+
8
+ class Tag < Ohm::Model
9
+ counter :total
10
+
11
+ def self.[](id)
12
+ super(encode(id)) || create(:id => encode(id))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # FieldMatter::Version
2
+ class FieldMatter
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # FieldMatter
3
+ # Author: Fielding Johnston
4
+
5
+ # bundler
6
+ require "bundler/setup"
7
+
8
+ # external
9
+ require "grit"
10
+ require "JSON"
11
+
12
+ # internal
13
+ require File.expand_path('../fieldmatter/strangematter', __FILE__)
14
+ require File.expand_path('../fieldmatter/darkmatter', __FILE__)
15
+ require File.expand_path('../fieldmatter/note', __FILE__)
16
+ require File.expand_path('../fieldmatter/tag', __FILE__)
17
+ require File.expand_path('../fieldmatter/version', __FILE__)
18
+
19
+ class FieldMatter
20
+
21
+ def initialize # eventually define common attr here and inherit to DarkMatter and StrangeMatter
22
+
23
+ end
24
+ end
25
+
26
+
27
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fieldmatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fielding Johnston
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-05 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Library used in the fieldnote personal content management system. I wrote
15
+ this library to assist in accessing extended attributes from support operating systems
16
+ and then transferring them, despite the git backend, to the fieldnote server. Once
17
+ there they are stored in a redis database for further manipulation.
18
+ email:
19
+ - fielding@justfielding.com
20
+ executables:
21
+ - fieldmatter
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - README.md
28
+ - bin/fieldmatter
29
+ - fieldmatter.gemspec
30
+ - git-hooks/post-commit
31
+ - git-hooks/post-receive
32
+ - lib/fieldmatter.rb
33
+ - lib/fieldmatter/darkmatter.rb
34
+ - lib/fieldmatter/note.rb
35
+ - lib/fieldmatter/strangematter.rb
36
+ - lib/fieldmatter/tag.rb
37
+ - lib/fieldmatter/version.rb
38
+ homepage: https://github.com/justfielding/fieldMatter
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project: fieldmatter
58
+ rubygems_version: 1.8.10
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: taxonomy with redis and extended attributes
62
+ test_files: []