frisky_mongo 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Pablo Fernandez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # frisky-mongo
2
+
3
+ Mongo backend for [Frisky](https://github.com/heelhook/frisky)
4
+
5
+ ## Credits
6
+
7
+ Pablo Fernandez: heelhook at littleq . net
8
+
9
+ ## Contributing
10
+
11
+ Once you've made your great commits:
12
+
13
+ 1. Fork
14
+ 2. Create a topic branch - `git checkout -b my_branch`
15
+ 3. Push to your branch - `git push origin my_branch`
16
+ 4. Create a [Pull Request](https://help.github.com/pull-requests/) from your branch
17
+ 5. That's it!
18
+
19
+ ## License
20
+
21
+ Copyright (c) 2012 Pablo Fernandez
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ "Software"), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require "bundler"
2
+
3
+ Bundler.setup
4
+ Bundler.require(:default)
5
+ require 'rake'
6
+ require 'rspec/core/rake_task'
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
9
+ require 'frisky-mongo/version'
10
+
11
+ RSpec::Core::RakeTask.new("spec") do |spec|
12
+ spec.pattern = "spec/**/*_spec.rb"
13
+ end
14
+
15
+ task gem: :build
16
+ task :build do
17
+ system "gem build frisky_mongo.gemspec"
18
+ end
19
+
20
+ task release: :build do
21
+ version = FriskyMongo::VERSION
22
+ system "git tag -a v#{version} -m 'Tagging #{version}'"
23
+ system "git push --tags"
24
+ system "gem push frisky_mongo-#{version}.gem"
25
+ system "rm frisky_mongo-#{version}.gem"
26
+ end
27
+
28
+ task default: :spec
@@ -0,0 +1,20 @@
1
+ module Frisky
2
+ @@mongo = nil
3
+ @@mongo_database = nil
4
+
5
+ CONFIG_EXTENSIONS ||= []
6
+ CONFIG_EXTENSIONS << :frisky_mongo_config=
7
+
8
+ def self.frisky_mongo_config=(config)
9
+ @@mongo = Mongo::Connection.from_uri(config['mongo']) if config['mongo']
10
+
11
+ if @@mongo
12
+ uri = URI.parse(config['mongo'])
13
+ @@mongo_database = uri.path.gsub(/^\//, '')
14
+ MongoMapper.connection = @@mongo
15
+ MongoMapper.database = @@mongo_database
16
+ end
17
+ end
18
+
19
+ def mongo; @@mongo; end
20
+ end
@@ -0,0 +1,46 @@
1
+ module Frisky
2
+ module Model
3
+ class Commit < ProxyBase
4
+ include MongoMapper::Document
5
+
6
+ primary_fetch do |args|
7
+ c = Commit.find(args[:id]) if args[:id]
8
+ c ||= Commit.where(args).first if args.any?
9
+ c or raise NotFound
10
+ end
11
+
12
+ key :author_id, ObjectId
13
+ key :message, String
14
+ key :parent_ids, Array
15
+ key :repository_id, ObjectId
16
+ key :stats, Hash
17
+ key :committer_id, ObjectId
18
+ key :files, Array
19
+ key :tree, String
20
+ key :date, Time
21
+ key :sha, String
22
+
23
+ belongs_to :author, class_name: 'Frisky::Model::Person'
24
+ belongs_to :committer, class_name: 'Frisky::Model::Person'
25
+ belongs_to :repository, class_name: 'Frisky::Model::Repository'
26
+
27
+ many :parents, in: :parent_ids, class_name: 'Frisky::Model::Commit'
28
+
29
+ proxy_methods author: lambda { Person.find(author_id) }
30
+ proxy_methods committer: lambda { Person.find(committer_id) }
31
+ proxy_methods repository: lambda { Repository.find(repository_id) }
32
+
33
+ def save(*args)
34
+ self.author.save if self.author
35
+ self.repository.save if self.repository
36
+ self.committer.save if self.committer
37
+
38
+ self.author_id ||= self.author.id if self.author
39
+ self.repository_id ||= self.repository.id
40
+ self.committer_id ||= self.committer.id if self.committer
41
+ self.parent_ids |= self.parents.map(&:id) if self.no_proxy_parents
42
+ super(*args)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,49 @@
1
+ module Frisky
2
+ module Model
3
+ class Event
4
+ include MongoMapper::Document
5
+
6
+ key :type, String
7
+ key :public, Boolean
8
+ key :payload, Hash
9
+ key :repository_id, ObjectId
10
+ key :actor_id, ObjectId
11
+ key :commit_ids, Array, default: nil
12
+ key :ref, String
13
+ key :head, String
14
+
15
+ belongs_to :actor, class_name: 'Frisky::Model::Person'
16
+ belongs_to :repository, class_name: 'Frisky::Model::Repository'
17
+
18
+ many :commits, in: :commit_ids, class_name: 'Frisky::Model::Commit'
19
+
20
+ def self.load_from_hashie(hashie)
21
+
22
+ e = Event.find(hashie.id)
23
+ e.actor = Person.find(e.actor_id)
24
+ e.repository = Repository.find(e.repository_id)
25
+ e.commits = e.commit_ids.map {|id| Commit.find(id) }
26
+ e
27
+ end
28
+
29
+ def serialize
30
+ # Save all related
31
+ self.actor.save!
32
+ self.repository.save!
33
+ self.commit_ids ||= []
34
+ self.commits.each {|c| c.save!; self.commit_ids << c._id unless self.commit_ids.include? c._id }
35
+
36
+ self.actor_id = self.actor.id
37
+ self.repository_id = self.repository.id
38
+
39
+ self.save!
40
+
41
+ self.to_json
42
+ end
43
+
44
+ def self.exists?(raw)
45
+ self.collection.find_one(type: raw.type, _id: raw.id) != nil
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ module Frisky
2
+ module Model
3
+ class Person < ProxyBase
4
+ include MongoMapper::Document
5
+
6
+ primary_fetch do |args|
7
+ p = Person.where(login: args[:login]).first if args[:login]
8
+ p ||= Person.where(email: args[:email]).first if args[:email]
9
+ p or raise NotFound
10
+ end
11
+
12
+ key :name, String
13
+ key :login, String
14
+ key :email, String
15
+ key :bio, String
16
+ key :location, String
17
+ key :blog, String
18
+ key :company, String
19
+ key :followers, Integer
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module Frisky
2
+ module Model
3
+ class Repository < ProxyBase
4
+ include MongoMapper::Document
5
+
6
+ primary_fetch do |args|
7
+ p = Repository.where(args).first if args.any?
8
+ p or raise NotFound
9
+ end
10
+
11
+ key :homepage, String
12
+ key :watchers_count, Integer
13
+ key :html_url, String
14
+ key :owner_id, ObjectId
15
+ key :master_branch, String
16
+ key :forks_count, Integer
17
+ key :git_url, String
18
+ key :full_name, String
19
+ key :name, String
20
+ key :url, String
21
+
22
+ timestamps!
23
+
24
+ belongs_to :owner, class_name: 'Frisky::Model::Person'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module FriskyMongo
2
+ VERSION = '0.7.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'frisky-mongo/version'
2
+ require 'frisky-mongo/config'
3
+
4
+ module Frisky
5
+ module Model
6
+ EXTENSIONS ||= []
7
+ EXTENSIONS << 'frisky-mongo/models/event'
8
+ EXTENSIONS << 'frisky-mongo/models/person'
9
+ EXTENSIONS << 'frisky-mongo/models/commit'
10
+ EXTENSIONS << 'frisky-mongo/models/repository'
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frisky_mongo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pablo Fernandez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongo_mapper
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: classproxy
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A mongodb backend for frisky data models
47
+ email:
48
+ - heelhook@littleq.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/frisky-mongo/config.rb
54
+ - lib/frisky-mongo/models/commit.rb
55
+ - lib/frisky-mongo/models/event.rb
56
+ - lib/frisky-mongo/models/person.rb
57
+ - lib/frisky-mongo/models/repository.rb
58
+ - lib/frisky-mongo/version.rb
59
+ - lib/frisky-mongo.rb
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ homepage:
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
76
+ - 0
77
+ hash: -4077309953568213348
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A mongodb backend for frisky
90
+ test_files: []