acts_as_cleo 0.0.1
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/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/acts_as_cleo.gemspec +17 -0
- data/lib/acts_as_cleo/result.rb +16 -0
- data/lib/acts_as_cleo/version.rb +3 -0
- data/lib/acts_as_cleo.rb +111 -0
- metadata +54 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Ignore bundler config
|
2
|
+
/.bundle
|
3
|
+
Gemfile.lock
|
4
|
+
|
5
|
+
#rvm
|
6
|
+
/.rvmrc
|
7
|
+
.rvmrc
|
8
|
+
|
9
|
+
*.gem
|
10
|
+
*.rbc
|
11
|
+
.bundle
|
12
|
+
.config
|
13
|
+
.yardoc
|
14
|
+
InstalledFiles
|
15
|
+
_yardoc
|
16
|
+
coverage
|
17
|
+
doc/
|
18
|
+
lib/bundler/man
|
19
|
+
pkg
|
20
|
+
rdoc
|
21
|
+
spec/reports
|
22
|
+
test/tmp
|
23
|
+
test/version_tmp
|
24
|
+
tmp
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Robert R. Meyer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ActsAsCleo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'acts_as_cleo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install acts_as_cleo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/acts_as_cleo/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Robert R. Meyer"]
|
6
|
+
gem.email = ["Blue.Dog.Archolite@gmail.com"]
|
7
|
+
gem.description = %q{A Cleo Inegration Gem}
|
8
|
+
gem.summary = %q{A Rails interface for the Cleo REST API}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "acts_as_cleo"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ActsAsCleo::VERSION
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Cleo
|
2
|
+
class Result
|
3
|
+
include HappyMapper
|
4
|
+
tag 'element'
|
5
|
+
|
6
|
+
has_many :term, String, :tag => 'term'
|
7
|
+
element :id, Integer
|
8
|
+
element :name, String
|
9
|
+
element :score, Float
|
10
|
+
element :timestamp, Time
|
11
|
+
element :title, String
|
12
|
+
element :url, String
|
13
|
+
|
14
|
+
alias :terms :term
|
15
|
+
end
|
16
|
+
end
|
data/lib/acts_as_cleo.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
module Cleo::ActsAsCleo
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
## Anything in here is done to all models
|
5
|
+
# def self.included(base)
|
6
|
+
# base.before_create :set_cleo_id
|
7
|
+
# base.after_commit :sync_with_cleo
|
8
|
+
# base.after_destroy :remove_from_cleo
|
9
|
+
#
|
10
|
+
# end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def acts_as_cleo(opts = {})
|
18
|
+
class_eval <<-EOV
|
19
|
+
include Cleo::ActsAsCleo::InstanceMethods
|
20
|
+
before_create :set_cleo_id
|
21
|
+
after_commit :sync_with_cleo
|
22
|
+
after_destroy :remove_from_cleo
|
23
|
+
|
24
|
+
cattr_accessor :cleo_config
|
25
|
+
|
26
|
+
#set type to query against in Cleo
|
27
|
+
#defaults to class name
|
28
|
+
#ie "User" when acts_as_cleo is included in user.b
|
29
|
+
self.cleo_config = {}
|
30
|
+
self.cleo_config[:type] = opts[:type] || self.ancestors.first.name
|
31
|
+
|
32
|
+
self.cleo_config[:name] = opts[:name]
|
33
|
+
|
34
|
+
#specify what columns to add as part of the xml object
|
35
|
+
#defaults to all columns in database
|
36
|
+
self.cleo_config[:terms] = opts[:terms] || self.column_names
|
37
|
+
self.cleo_config[:terms] = self.cleo_config[:terms] - opts[:except] unless opts[:except].blank?
|
38
|
+
|
39
|
+
#figure out what the score param is. execute the self.send(#{opts[:score].to_s}.count)
|
40
|
+
self.cleo_config[:score] = opts[:score]
|
41
|
+
|
42
|
+
def query(query, opts = {})
|
43
|
+
Cleo.query(query)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cleo_id
|
47
|
+
record_type = self.cleo_config[:type]
|
48
|
+
return nil unless self.id
|
49
|
+
end
|
50
|
+
|
51
|
+
def cleo_id= ( new_id)
|
52
|
+
end
|
53
|
+
|
54
|
+
EOV
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
module InstanceMethods
|
61
|
+
# callback hooks to keep cleo insync with data
|
62
|
+
def sync_with_cleo
|
63
|
+
return if self.is_a?(Moderation)
|
64
|
+
return if self.is_a?(Audit)
|
65
|
+
|
66
|
+
if self.persisted?
|
67
|
+
Cleo.update(self)
|
68
|
+
else
|
69
|
+
Cleo.create(self)
|
70
|
+
end
|
71
|
+
#after_update send the data to cleo
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_cleo_id
|
75
|
+
self.cleo_id = Time.now.to_i unless self.is_a?(Moderation) || self.is_a?(Audit)
|
76
|
+
end
|
77
|
+
|
78
|
+
def remove_from_cleo
|
79
|
+
return if self.is_a?(Moderation)
|
80
|
+
return if self.is_a?(Audit)
|
81
|
+
Cleo.delete(self) if self.persisted?
|
82
|
+
end
|
83
|
+
#end callback hooks
|
84
|
+
|
85
|
+
def to_cleo_result
|
86
|
+
#take self and change it into a Cleo::Result and return
|
87
|
+
cr = Cleo::Result.new
|
88
|
+
cr.term = []
|
89
|
+
|
90
|
+
self.cleo_config[:terms].each do |term|
|
91
|
+
cr.term << self.send(term).to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
cr.term = cr.term.compact.reject(&:blank?)
|
95
|
+
self.cleo_id ||= Time.now.to_i
|
96
|
+
cr.id = self.cleo_id || Time.now.to_i
|
97
|
+
|
98
|
+
cr.name = self.send(self.cleo_config[:name]).to_s
|
99
|
+
cr.name = cr.term.first if cr.name.blank?
|
100
|
+
|
101
|
+
score = self.send(self.cleo_config[:score])
|
102
|
+
cr.score = score.nil? ? 0 : score.count
|
103
|
+
|
104
|
+
cr
|
105
|
+
end
|
106
|
+
|
107
|
+
alias :as_cleo :to_cleo_result
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
ActiveRecord::Base.send :include, Cleo::ActsAsCleo
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_cleo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robert R. Meyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-20 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Cleo Inegration Gem
|
15
|
+
email:
|
16
|
+
- Blue.Dog.Archolite@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- acts_as_cleo.gemspec
|
27
|
+
- lib/acts_as_cleo.rb
|
28
|
+
- lib/acts_as_cleo/result.rb
|
29
|
+
- lib/acts_as_cleo/version.rb
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.17
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: A Rails interface for the Cleo REST API
|
54
|
+
test_files: []
|