simple_form_ransack 0.0.7 → 0.0.8

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: 8bf0d09cf759f75b2f06b555c2ab33721f06d36b
4
- data.tar.gz: 8a54387e3b835ebd68a53a61c9773e1b5023c0ac
3
+ metadata.gz: c763fb28de54e7cce0d673dbef3f9a9087e9330d
4
+ data.tar.gz: 9bca32d430e9d66876a8b93facbc68109368f691
5
5
  SHA512:
6
- metadata.gz: e687398d0bd4dcc8e8eeab8dcbf0c795e38028a5910209b758e10e897304b3c63c0966fe3cee3f1076416b5b24218e112d48d319a6156cee493b96d7bd191c7b
7
- data.tar.gz: 85766928afba1b324409900f0a273b09fec46ffab504468a0177973e161c8ffa32dec4dad27419cd23b086d2b0851ddf122db49feb4fdaf82a83cf414943071d
6
+ metadata.gz: b8dc68e1dac428ddda09f0d4311851780d5bc9aa4329e1d2865c6b593b4525caa13001f6ec5e24842a382960c1f25606ca9fc6794fcd232ab4de45559e3a8173
7
+ data.tar.gz: f4696e0b19efb0cfcdcc631d11f0c439757965cbcac459967d52c0915a41f5a99cc481bdaa21dcc8c2bfd475b9a9b45ff395be94fc22f1669344047b8d842db5
@@ -5,21 +5,21 @@ module SimpleFormRansackHelper
5
5
  else
6
6
  opts = {}
7
7
  end
8
-
8
+
9
9
  opts[:url] = request.original_fullpath unless opts[:url]
10
10
  opts[:method] = "get" unless opts[:method]
11
11
  args << opts
12
-
12
+
13
13
  model_class = resource.klass
14
14
  sample_model = model_class.new
15
-
15
+
16
16
  simple_form_for(sample_model, *args) do |form|
17
17
  form_proxy = SimpleFormRansack::FormProxy.new(
18
- :resource => resource,
19
- :form => form,
20
- :params => params,
18
+ resource: resource,
19
+ form: form,
20
+ params: params,
21
21
  )
22
-
22
+
23
23
  yield form_proxy
24
24
  end
25
25
  end
@@ -1,6 +1,6 @@
1
1
  module SimpleFormRansack
2
2
  autoload :AttributeInspector, "simple_form_ransack/attribute_inspector"
3
+ autoload :FormProxy, 'simple_form_ransack/form_proxy'
3
4
  end
4
5
 
5
6
  require_relative "../app/helpers/simple_form_ransack_helper"
6
- require_relative "simple_form_ransack/form_proxy"
@@ -7,22 +7,22 @@ class SimpleFormRansack::AttributeInspector
7
7
  @instance = args[:instance]
8
8
  @clazz = args[:clazz]
9
9
  @debug = args[:debug]
10
-
10
+
11
11
  @generated_name_classes = []
12
12
  @models = []
13
13
  @current_clazz = @clazz
14
14
  @name_builtup = []
15
-
15
+
16
16
  has_attribute_directly = @clazz.attribute_names.select{ |name| name.to_s == @ransack_name.to_s }.any?
17
-
17
+
18
18
  research unless has_attribute_directly
19
19
  end
20
-
20
+
21
21
  # Loop through the name parts and inspectors reflections with it.
22
22
  def research
23
23
  @name_parts.each_with_index do |name_part, index|
24
24
  @name_builtup << name_part
25
-
25
+
26
26
  # The last part should be the attribute name.
27
27
  if index == @name_parts.length - 1
28
28
  if attribute_result = attribute_by_builtup
@@ -34,60 +34,60 @@ class SimpleFormRansack::AttributeInspector
34
34
  next
35
35
  end
36
36
  end
37
-
37
+
38
38
  # Try next - maybe next key need to be added? (which is common!)
39
39
  next unless reflection_result = reflection_by_builtup
40
-
40
+
41
41
  @name_builtup = []
42
42
  name = reflection_result[:name]
43
43
  reflection = reflection_result[:reflection]
44
-
44
+
45
45
  puts "Name: #{name}" if @debug
46
46
  puts "Reflection: #{reflection}" if @debug
47
-
47
+
48
48
  @current_clazz = reflection.klass
49
- @generated_name_classes << {:clazz => @current_clazz, :reflection => reflection}
49
+ @generated_name_classes << {clazz: @current_clazz, reflection: reflection}
50
50
  end
51
51
  end
52
-
52
+
53
53
  # Returns true if a complicated label could be generated and simple form should not do this itself.
54
54
  def generated_label?
55
55
  return true if @attribute && @generated_name_classes.any?
56
56
  return false
57
57
  end
58
-
58
+
59
59
  # Generates the complicated label and returns it.
60
60
  def generated_label
61
61
  name = ""
62
-
62
+
63
63
  if @generated_name_classes.last
64
64
  clazz, reflection = @generated_name_classes.last[:clazz], @generated_name_classes.last[:reflection]
65
65
  if reflection.collection?
66
- name << clazz.model_name.human(:count => 2)
66
+ name << clazz.model_name.human(count: 2)
67
67
  else
68
68
  name << clazz.model_name.human
69
69
  end
70
70
  end
71
-
71
+
72
72
  name << " " unless name.empty?
73
73
  name << @current_clazz.human_attribute_name(@attribute).to_s.downcase
74
-
74
+
75
75
  return name
76
76
  end
77
-
77
+
78
78
  private
79
-
79
+
80
80
  def reflection_by_builtup
81
81
  total_name = @name_builtup.join("_")
82
- result = @current_clazz.reflections.select{ |name, reflection| name.to_s == total_name }.first
83
- return {:name => result[0], :reflection => result[1]} if result
82
+ result = @current_clazz.reflections.select { |name, reflection| name.to_s == total_name }.first
83
+ return {name: result[0], reflection: result[1]} if result
84
84
  return false
85
85
  end
86
-
86
+
87
87
  def attribute_by_builtup
88
88
  total_name = @name_builtup.join("_")
89
- result = @current_clazz.attribute_names.select{ |name| name.to_s == total_name }.first
90
- return {:name => result} if result
89
+ result = @current_clazz.attribute_names.select { |name| name.to_s == total_name }.first
90
+ return {name: result} if result
91
91
  return false
92
92
  end
93
93
  end
@@ -5,56 +5,56 @@ class SimpleFormRansack::FormProxy
5
5
  @class = @resource.klass
6
6
  @params = args[:params]
7
7
  @form = args[:form]
8
-
8
+
9
9
  raise "No params given in arguments: #{args.keys}" unless @params
10
10
  end
11
-
11
+
12
12
  def input(name, *args)
13
13
  if args.last.is_a?(Hash)
14
14
  opts = args.pop
15
15
  else
16
16
  opts = {}
17
17
  end
18
-
18
+
19
19
  attribute_name = real_name(name, opts)
20
20
  as = as_from_opts(attribute_name, opts)
21
21
  input_html = opts.delete(:input_html) || {}
22
22
  set_value(as, name, opts, input_html)
23
23
  set_name(as, name, input_html)
24
24
  set_label(attribute_name, opts, input_html)
25
-
25
+
26
26
  opts[:required] = false unless opts.key?(:required)
27
27
  opts[:input_html] = input_html
28
28
  args << opts
29
29
  return @form.input(attribute_name, *args)
30
30
  end
31
-
31
+
32
32
  def method_missing(method_name, *args, &blk)
33
33
  @form.__send__(method_name, *args, &blk)
34
34
  end
35
-
35
+
36
36
  private
37
-
37
+
38
38
  def set_label(attribute_name, opts, input_html)
39
39
  if !opts.key?(:label)
40
40
  attribute_inspector = ::SimpleFormRansack::AttributeInspector.new(
41
- :name => attribute_name,
42
- :instance => @object,
43
- :clazz => @class
41
+ name: attribute_name,
42
+ instance: @object,
43
+ clazz: @class
44
44
  )
45
45
  if attribute_inspector.generated_label?
46
46
  opts[:label] = attribute_inspector.generated_label
47
47
  end
48
48
  end
49
49
  end
50
-
50
+
51
51
  def set_name(as, name, input_html)
52
52
  unless input_html.key?(:name)
53
53
  input_html[:name] = "q[#{name}]"
54
54
  input_html[:name] << "[]" if as == "check_boxes"
55
55
  end
56
56
  end
57
-
57
+
58
58
  def set_value(as, name, opts, input_html)
59
59
  if as == "select"
60
60
  if !opts.key?(:selected)
@@ -90,7 +90,7 @@ private
90
90
  end
91
91
  end
92
92
  end
93
-
93
+
94
94
  def as_list?(opts)
95
95
  if as_from_opts(opts) == "select"
96
96
  return true
@@ -98,23 +98,23 @@ private
98
98
  return false
99
99
  end
100
100
  end
101
-
101
+
102
102
  def as_from_opts(attribute_name, opts)
103
103
  if opts[:as].present?
104
104
  return opts[:as].to_s
105
- elsif opts[:collection]
105
+ elsif opts[:collection] || attribute_name.end_with?('country')
106
106
  return "select"
107
107
  end
108
-
108
+
109
109
  if column = @class.columns_hash[attribute_name]
110
110
  if column.type == :boolean
111
111
  return "boolean"
112
112
  end
113
113
  end
114
-
114
+
115
115
  return "text"
116
116
  end
117
-
117
+
118
118
  def real_name(name, opts)
119
119
  match = name.to_s.match(/^(.+)_(eq|cont|eq_any|gteq|lteq|gt|lt)$/)
120
120
  if match
@@ -1,3 +1,3 @@
1
1
  module SimpleFormRansack
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-31 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: country_select
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: codeclimate-test-reporter
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
185
  version: '0'
172
186
  requirements: []
173
187
  rubyforge_project:
174
- rubygems_version: 2.4.0
188
+ rubygems_version: 2.2.2
175
189
  signing_key:
176
190
  specification_version: 4
177
191
  summary: Ransack and SimpleForm combined.