dca 0.1.0 → 0.1.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/Rakefile +2 -2
- data/VERSION +1 -1
- data/dca.gemspec +3 -3
- data/lib/dca/commands/area.rb +1 -1
- data/lib/dca/config.rb +2 -0
- data/lib/dca/models/nokogiri_binder.rb +6 -1
- data/lib/dca/storage/elasticsearch_storage.rb +20 -11
- data/lib/dca/storage/mongo_storage.rb +16 -4
- data/spec/binder_spec.rb +16 -0
- data/spec/mock/page.rb +5 -1
- data/spec/mock/position.rb +5 -5
- metadata +4 -4
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ require 'jeweler'
|
|
16
16
|
Jeweler::Tasks.new do |gem|
|
17
17
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
18
|
gem.name = "dca"
|
19
|
-
gem.homepage = "http://github.com/
|
19
|
+
gem.homepage = "http://github.com/maxkazar/dca"
|
20
20
|
gem.license = "MIT"
|
21
21
|
gem.summary = %Q{DCA}
|
22
22
|
gem.description = %Q{DCA}
|
@@ -45,4 +45,4 @@ YARD::Rake::YardocTask.new
|
|
45
45
|
|
46
46
|
SYS_ENV = 'development'
|
47
47
|
require './lib/dca'
|
48
|
-
require 'resque/tasks'
|
48
|
+
require 'resque/tasks'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/dca.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "dca"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Maxim Kazarin"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-08-10"
|
13
13
|
s.description = "DCA"
|
14
14
|
s.email = "maxkazargm@gmail.com"
|
15
15
|
s.executables = ["dca"]
|
@@ -88,7 +88,7 @@ Gem::Specification.new do |s|
|
|
88
88
|
"spec/spec_helper.rb",
|
89
89
|
"spec/support/storage_examples.rb"
|
90
90
|
]
|
91
|
-
s.homepage = "http://github.com/
|
91
|
+
s.homepage = "http://github.com/maxkazar/dca"
|
92
92
|
s.licenses = ["MIT"]
|
93
93
|
s.require_paths = ["lib"]
|
94
94
|
s.rubygems_version = "1.8.24"
|
data/lib/dca/commands/area.rb
CHANGED
@@ -101,7 +101,7 @@ module DCA
|
|
101
101
|
ops[:err] = debug_file
|
102
102
|
ops[:out] = debug_file
|
103
103
|
end
|
104
|
-
env_vars = {'QUEUE' => queue}
|
104
|
+
env_vars = {'QUEUE' => queue, 'SYS_ENV' => SYS_ENV}
|
105
105
|
|
106
106
|
count.times {
|
107
107
|
## Using Kernel.spawn and Process.detach because regular system() call would
|
data/lib/dca/config.rb
CHANGED
@@ -33,7 +33,12 @@ module DCA
|
|
33
33
|
type = params[:type]
|
34
34
|
type = find_type object, params[:field], options[:polymorphic] if type.nil? || options[:polymorphic]
|
35
35
|
|
36
|
-
|
36
|
+
unless selector.nil?
|
37
|
+
result = content.css(selector)
|
38
|
+
result = object.send(options[:parser], result) unless options[:parser].nil?
|
39
|
+
|
40
|
+
result = result.map { |node| type.new.bind node } unless result.nil?
|
41
|
+
end
|
37
42
|
result
|
38
43
|
end
|
39
44
|
|
@@ -5,7 +5,7 @@ module DCA
|
|
5
5
|
def initialize(connection, context, options = {})
|
6
6
|
@connection = connection
|
7
7
|
@index = options[:index] || DCA.project_name.underscore
|
8
|
-
@type = options[:type] || context
|
8
|
+
@type = options[:type] || get_alias(context)
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.establish_connection(config)
|
@@ -13,7 +13,6 @@ module DCA
|
|
13
13
|
Tire.configure { url "http://#{config[:host]}:#{config[:port]}" }
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
def state position
|
18
17
|
item = find position
|
19
18
|
return :create if item.nil?
|
@@ -26,7 +25,7 @@ module DCA
|
|
26
25
|
|
27
26
|
def find position
|
28
27
|
return nil if position.base_id.nil?
|
29
|
-
query = Tire.search(@index, :
|
28
|
+
query = Tire.search(@index, type: type) { query { term :base_id, position.base_id } }
|
30
29
|
query.results.first
|
31
30
|
end
|
32
31
|
|
@@ -36,8 +35,7 @@ module DCA
|
|
36
35
|
|
37
36
|
def create(item)
|
38
37
|
item.updated_at = item.created_at = Time.now.utc
|
39
|
-
data = item
|
40
|
-
data[:type] = type
|
38
|
+
data = hash_from item
|
41
39
|
|
42
40
|
result = Tire.index(@index).store data
|
43
41
|
Tire.index(@index).refresh
|
@@ -46,9 +44,7 @@ module DCA
|
|
46
44
|
end
|
47
45
|
|
48
46
|
def update(item)
|
49
|
-
data = item
|
50
|
-
data[:type] = type
|
51
|
-
|
47
|
+
data = hash_from item
|
52
48
|
Tire.index(@index) do
|
53
49
|
store data
|
54
50
|
refresh
|
@@ -56,8 +52,7 @@ module DCA
|
|
56
52
|
end
|
57
53
|
|
58
54
|
def remove(item)
|
59
|
-
data = item
|
60
|
-
data[:type] = type
|
55
|
+
data = hash_from item
|
61
56
|
|
62
57
|
Tire.index(@index) do
|
63
58
|
remove data
|
@@ -73,8 +68,22 @@ module DCA
|
|
73
68
|
|
74
69
|
def context object
|
75
70
|
result = self.clone
|
76
|
-
result.instance_variable_set :@type, object
|
71
|
+
result.instance_variable_set :@type, get_alias(object)
|
77
72
|
result
|
78
73
|
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def hash_from(item)
|
78
|
+
data = item.to_hash
|
79
|
+
data[:_id] = data[:id] if data[:id]
|
80
|
+
data.delete(:id)
|
81
|
+
data[:type] = type
|
82
|
+
data
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_alias object
|
86
|
+
object.respond_to?(:alias) ? object.alias : object.to_s.demodulize.downcase.pluralize
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
@@ -5,7 +5,7 @@ module DCA
|
|
5
5
|
def initialize(connection, context, options = {})
|
6
6
|
@database = connection.db(options[:database] || DCA.project_name.underscore)
|
7
7
|
@connection = connection
|
8
|
-
@collection = database.collection(options[:collection] || context
|
8
|
+
@collection = database.collection(options[:collection] || get_alias(context))
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.establish_connection(config)
|
@@ -31,11 +31,11 @@ module DCA
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def create(item)
|
34
|
-
item.id = collection.insert item
|
34
|
+
item.id = collection.insert hash_from item
|
35
35
|
end
|
36
36
|
|
37
37
|
def update(item)
|
38
|
-
collection.update({_id: item.id}, item
|
38
|
+
collection.update({_id: item.id}, hash_from(item))
|
39
39
|
end
|
40
40
|
|
41
41
|
def remove(item)
|
@@ -44,8 +44,20 @@ module DCA
|
|
44
44
|
|
45
45
|
def context object
|
46
46
|
result = self.clone
|
47
|
-
result.instance_variable_set :@collection, result.database.collection(object
|
47
|
+
result.instance_variable_set :@collection, result.database.collection(get_alias object)
|
48
48
|
result
|
49
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def hash_from(item)
|
54
|
+
data = item.to_hash
|
55
|
+
data.delete(:id)
|
56
|
+
data
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_alias object
|
60
|
+
object.respond_to?(:alias) ? object.alias : object.to_s.demodulize.downcase.pluralize
|
61
|
+
end
|
50
62
|
end
|
51
63
|
end
|
data/spec/binder_spec.rb
CHANGED
@@ -64,6 +64,22 @@ describe 'Binder' do
|
|
64
64
|
page.bind Nokogiri::HTML open('./spec/fixtures/page.html')
|
65
65
|
|
66
66
|
page.positions.should have(6).items
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'parser option' do
|
70
|
+
it 'should be used for has_many association' do
|
71
|
+
page = Mock::PageExt.new :category => :full
|
72
|
+
page.should_receive(:positions_parser)
|
73
|
+
page.bind Nokogiri::HTML open('./spec/fixtures/page.html')
|
74
|
+
end
|
67
75
|
|
76
|
+
it 'should change items collections for has_many association' do
|
77
|
+
page = Mock::PageExt.new :category => :full
|
78
|
+
page.should_receive(:positions_parser) do |items|
|
79
|
+
items[0,2]
|
80
|
+
end
|
81
|
+
page.bind Nokogiri::HTML open('./spec/fixtures/page.html')
|
82
|
+
page.positions.should have(2).items
|
83
|
+
end
|
68
84
|
end
|
69
85
|
end
|
data/spec/mock/page.rb
CHANGED
@@ -7,7 +7,11 @@ module DCA
|
|
7
7
|
|
8
8
|
class PageExt < DCA::Models::BaseModel
|
9
9
|
attr_accessor :category
|
10
|
-
has_many :positions, :selector => 'li', :
|
10
|
+
has_many :positions, :selector => 'li', polymorphic: :category, append: true, parser: :positions_parser
|
11
|
+
|
12
|
+
def positions_parser items
|
13
|
+
items
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/spec/mock/position.rb
CHANGED
@@ -11,17 +11,17 @@ module DCA
|
|
11
11
|
class Position < DCA::Models::Position
|
12
12
|
attr_accessor :raise, :failed, :title
|
13
13
|
|
14
|
-
has_one :base_id, :integer, :
|
15
|
-
has_one :title, :string, :
|
14
|
+
has_one :base_id, :integer, selector: 'a', attribute: :href, regex: /(\d+)$/
|
15
|
+
has_one :title, :string, selector: 'a'
|
16
16
|
end
|
17
17
|
|
18
18
|
class ExtPosition < Position
|
19
|
-
has_one :description, :string, :
|
20
|
-
has_one :date, :datetime, :
|
19
|
+
has_one :description, :string, selector: 'span.description'
|
20
|
+
has_one :date, :datetime, selector: 'span.date'
|
21
21
|
end
|
22
22
|
|
23
23
|
class FullPosition < Position
|
24
|
-
has_one :base_id, :string, :
|
24
|
+
has_one :base_id, :string, selector: 'a'
|
25
25
|
end
|
26
26
|
|
27
27
|
class ChildPosition < DCA::Models::Position
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ohm
|
@@ -377,7 +377,7 @@ files:
|
|
377
377
|
- spec/redis_notifier_spec.rb
|
378
378
|
- spec/spec_helper.rb
|
379
379
|
- spec/support/storage_examples.rb
|
380
|
-
homepage: http://github.com/
|
380
|
+
homepage: http://github.com/maxkazar/dca
|
381
381
|
licenses:
|
382
382
|
- MIT
|
383
383
|
post_install_message:
|
@@ -392,7 +392,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
392
392
|
version: '0'
|
393
393
|
segments:
|
394
394
|
- 0
|
395
|
-
hash:
|
395
|
+
hash: -922341340546014449
|
396
396
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
397
397
|
none: false
|
398
398
|
requirements:
|