constructorio-rails 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: add856357061727733d8d0e8bb7dfe491ba969b9
4
- data.tar.gz: 29bb42d24dc96b9190275c62d2d09dcf809a81a3
3
+ metadata.gz: dd5d18714587d0bc7f2a13404db2cacb6edc64fa
4
+ data.tar.gz: 3479eef17cc810bad46006e8368b011161d99875
5
5
  SHA512:
6
- metadata.gz: 94dfec7c4db091d29510a6a3afabccf02eba9bd4315ddec7932e6cc84ebb704d4078f08aa047e628084172ef22e8af3fcccac8bc5ce13d3056593ce10de8fe8d
7
- data.tar.gz: 416a0a64e00cd0f31e03d371273ff344101dbad77f6c13cba8ca3bc32927da71c36c6b320370f39099334d0b19ff633dc5749473fe1616f3e1a8f18af887545a
6
+ metadata.gz: e2b7ce1daf7d02a7cd42a3bb740992dc439696c84514623d34b9d2cf42b3fc9d8cc6022c4542ab81e7435794262acf55d5953304e8b42768e4a2d72a44b98178
7
+ data.tar.gz: 0e967a97779b3a69ac7ee6b0ce264ba21fa5510d19ec541a120b4e15a15a53d3a8aee92ed31874ba6d55d3d9696f270fe2f32d0094692fa0b949b6a96b917ae1
@@ -40,7 +40,9 @@ module ConstructorIORails
40
40
  # "product_name", "description"
41
41
  # - or -
42
42
  # { 'attribute' => 'product_name', 'metadata' => { metadata_one => ->{ something_dynamic }} }
43
- def constructorio_autocomplete(fields, autocomplete_key = ConstructorIORails.configuration.autocomplete_key)
43
+ def constructorio_autocomplete(fields,
44
+ autocomplete_key = ConstructorIORails.configuration.autocomplete_key,
45
+ autocomplete_section = ConstructorIORails.configuration.autocomplete_section)
44
46
  # All fields require an attribute
45
47
  field_names = fields.map { |f| f.is_a?(String) ? f : f['attribute'] }
46
48
  raise MissingItemName if field_names.include? nil
@@ -62,31 +64,34 @@ module ConstructorIORails
62
64
  after_save do |record|
63
65
  updated_fields = record.changed.select { |c| field_names.include? c }
64
66
  updated_fields.each do |field|
65
- record.send(:constructorio_add_record, record[field.to_sym], transformed[field], autocomplete_key)
67
+ record.send(:constructorio_add_record, record[field.to_sym], transformed[field], autocomplete_key, autocomplete_section)
66
68
  end
67
69
  end
68
70
 
69
71
  before_destroy do |record|
70
72
  field_names.each do |field|
71
- record.send(:constructorio_delete_record, record[field.to_sym], transformed[field], autocomplete_key)
73
+ record.send(:constructorio_delete_record, record[field.to_sym], transformed[field], autocomplete_key, autocomplete_section)
72
74
  end
73
75
  end
74
76
  end
75
77
  end
76
78
 
77
79
  module InstanceMethods
78
- def constructorio_add_record(value, metadata = {}, autocomplete_key)
79
- constructorio_call_api("post", value, metadata, autocomplete_key)
80
+ def constructorio_add_record(value, metadata = {}, autocomplete_key, autocomplete_section)
81
+ constructorio_call_api("post", value, metadata, autocomplete_key, autocomplete_section)
80
82
  end
81
83
 
82
- def constructorio_delete_record(value, metadata = {}, autocomplete_key)
83
- constructorio_call_api("delete", value, metadata, autocomplete_key)
84
+ def constructorio_delete_record(value, metadata = {}, autocomplete_key, autocomplete_section)
85
+ constructorio_call_api("delete", value, metadata, autocomplete_key, autocomplete_section)
84
86
  end
85
87
 
86
88
  private
87
89
 
88
- def constructorio_make_request_body(value, metadata)
89
- request_body = { "item_name" => "#{value}" }
90
+ def constructorio_make_request_body(value, metadata, autocomplete_section)
91
+ request_body = {
92
+ "item_name" => "#{value}",
93
+ "autocomplete_section" => autocomplete_section
94
+ }
90
95
  unless metadata.empty?
91
96
  metadata.each do |k, v|
92
97
  v = instance_exec(&v) if v.is_a? Proc
@@ -96,13 +101,13 @@ module ConstructorIORails
96
101
  request_body
97
102
  end
98
103
 
99
- def constructorio_call_api(method, value, metadata, autocomplete_key)
104
+ def constructorio_call_api(method, value, metadata, autocomplete_key, autocomplete_section)
100
105
  api_token = ConstructorIORails.configuration.api_token
101
106
  api_url = ConstructorIORails.configuration.api_url || "https://ac.cnstrc.com/"
102
107
  @http_client ||= Faraday.new(url: api_url)
103
108
  @http_client.basic_auth(api_token, '')
104
109
 
105
- request_body = constructorio_make_request_body(value, metadata)
110
+ request_body = constructorio_make_request_body(value, metadata, autocomplete_section)
106
111
  constructorio_send_request(method, @http_client, request_body, autocomplete_key)
107
112
  end
108
113
 
@@ -1,5 +1,5 @@
1
1
  module ConstructorIORails
2
2
  class Configuration
3
- attr_accessor :api_token, :autocomplete_key, :api_url
3
+ attr_accessor :api_token, :autocomplete_key, :api_url, :autocomplete_section
4
4
  end
5
5
  end
@@ -10,13 +10,13 @@ namespace :constructorio do
10
10
  namespace :import do
11
11
  desc import_model_desc
12
12
 
13
- task :model do
13
+ task :model => :environment do
14
14
  klass = eval(ENV['CLASS'].to_s)
15
15
  fields = ConstructorIORails::Fields.instance.list(klass.model_name)
16
16
  if fields.any?
17
17
  klass.all.each do |record|
18
18
  fields.each do |field|
19
- klass.add_record(record[field.to_sym], ConstructorIORails.configuration.autocomplete_key)
19
+ record.constructorio_add_record(record[field.to_sym], {}, ConstructorIORails.configuration.autocomplete_key, ConstructorIORails.configuration.autocomplete_section)
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module ConstructorIORails
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructorio-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Lai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-21 00:00:00.000000000 Z
11
+ date: 2016-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord