administrate 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of administrate might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 110c076246ab6939cc37da4ede75207b571adf4b
4
- data.tar.gz: 78aa661a2b45c16533009ad19fe820b3bb2cd767
3
+ metadata.gz: 683ee0c8cf867c553a2c367063d9112cd8ff968f
4
+ data.tar.gz: be6336fc10bc73444eb2d42a5c95f7519252dc42
5
5
  SHA512:
6
- metadata.gz: 388dc4bfd5a7a92bb8f027790625ca6286afedf90ef37309dac57f735abc7176ff9c394a23f191a79d08442c31a134eaf00bb8226813dc74b438c7ceb4ff373f
7
- data.tar.gz: 92b2e3901c5e94ce0597a60ca518fc45f0814bc95ee6d0222839b39e34aad28aad14e96d17ee39270ba7f20304267b10d23b96d9f65a03721543b214920ed1a5
6
+ metadata.gz: 84a3b33e1464a4aff24661891d7333c71bd1809131994cb7af9993735230e81765fffcf0f90dc861e79fa006a06a26ca8dda37b5a045221b1e6ac13c55d0d669
7
+ data.tar.gz: ca89ca985db441fb3aa69bf6dfe4e5ddee6d268a1c1b034a64eac8b0a5b0b6bb27986a7f9ed359d4c48fac6c9ce0238edee87ced64bf667f89fefa783ab98c01
@@ -0,0 +1,7 @@
1
+ <%= f.label has_one.permitted_attribute %>
2
+ <%= f.collection_select(
3
+ has_one.permitted_attribute,
4
+ has_one.candidate_records,
5
+ :id,
6
+ :to_s,
7
+ ) %>
@@ -0,0 +1,3 @@
1
+ <% if has_one.data %>
2
+ <%= link_to has_one.data, [Administrate::NAMESPACE, has_one.data] %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% if has_one.data %>
2
+ <%= link_to has_one.data, [Administrate::NAMESPACE, has_one.data] %>
3
+ <% end %>
@@ -1,36 +1,18 @@
1
1
  require "administrate/fields/belongs_to"
2
2
  require "administrate/fields/email"
3
3
  require "administrate/fields/has_many"
4
+ require "administrate/fields/has_one"
4
5
  require "administrate/fields/image"
5
6
  require "administrate/fields/string"
6
7
 
7
8
  module Administrate
8
9
  class BaseDashboard
10
+ include Administrate
11
+
9
12
  def permitted_attributes
10
13
  form_attributes.map do |attr|
11
- field_class(attr).permitted_attribute(attr)
14
+ attribute_types[attr].permitted_attribute(attr)
12
15
  end.uniq
13
16
  end
14
-
15
- def field_class(attr)
16
- field_registry.fetch(attribute_types[attr])
17
- end
18
-
19
- private
20
-
21
- def field_registry
22
- {
23
- belongs_to: Administrate::Field::BelongsTo,
24
- boolean: Administrate::Field::String,
25
- datetime: Administrate::Field::String,
26
- email: Administrate::Field::Email,
27
- float: Administrate::Field::String,
28
- has_many: Administrate::Field::HasMany,
29
- image: Administrate::Field::Image,
30
- integer: Administrate::Field::String,
31
- string: Administrate::Field::String,
32
- text: Administrate::Field::String,
33
- }
34
- end
35
17
  end
36
18
  end
@@ -1,10 +1,17 @@
1
+ require_relative "deferred"
2
+
1
3
  module Administrate
2
4
  module Field
3
5
  class Base
4
- def initialize(attribute, data, page)
6
+ def self.with_options(options = {})
7
+ Deferred.new(self, options)
8
+ end
9
+
10
+ def initialize(attribute, data, page, options = {})
5
11
  @attribute = attribute
6
12
  @data = data
7
13
  @page = page
14
+ @options = options
8
15
  end
9
16
 
10
17
  def self.permitted_attribute(attr)
@@ -0,0 +1,20 @@
1
+ module Administrate
2
+ module Field
3
+ class Deferred
4
+ def initialize(klass, options = {})
5
+ @klass = klass
6
+ @options = options
7
+ end
8
+
9
+ def new(*args)
10
+ klass.new(*args, options)
11
+ end
12
+
13
+ delegate :permitted_attribute, to: :klass
14
+
15
+ private
16
+
17
+ attr_reader :klass, :options
18
+ end
19
+ end
20
+ end
@@ -31,7 +31,7 @@ module Administrate
31
31
  end
32
32
 
33
33
  def resource_class_name
34
- attribute.to_s.singularize.camelcase
34
+ @options[:class_name] || attribute.to_s.singularize.camelcase
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,11 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class HasOne < BelongsTo
6
+ def self.permitted_attribute(attr)
7
+ attr
8
+ end
9
+ end
10
+ end
11
+ end
@@ -16,7 +16,7 @@ module Administrate
16
16
  value = resource.public_send(attribute_name)
17
17
 
18
18
  dashboard.
19
- field_class(attribute_name).
19
+ attribute_types[attribute_name].
20
20
  new(attribute_name, value, page)
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -25,22 +25,47 @@ module Administrate
25
25
  end
26
26
 
27
27
  def field_type(attribute)
28
- klass.type_for_attribute(attribute).type ||
28
+ if klass.type_for_attribute(attribute).type
29
+ default_field_type
30
+ else
29
31
  association_type(attribute)
32
+ end
33
+ end
34
+
35
+ def default_field_type
36
+ "Field::String"
30
37
  end
31
38
 
32
39
  def association_type(attribute)
33
40
  reflection = klass.reflections[attribute.to_s]
34
- if reflection.collection?
35
- :has_many
41
+ if reflection.has_one?
42
+ "Field::HasOne"
43
+ elsif reflection.collection?
44
+ "Field::HasMany" + has_many_options_string(reflection)
36
45
  else
37
- :belongs_to
46
+ "Field::BelongsTo"
38
47
  end
39
48
  end
40
49
 
41
50
  def klass
42
51
  @klass ||= Object.const_get(class_name)
43
52
  end
53
+
54
+ def has_many_options_string(reflection)
55
+ if reflection.class_name != reflection.name.to_s.classify
56
+ options_string(class_name: reflection.class_name)
57
+ else
58
+ ""
59
+ end
60
+ end
61
+
62
+ def options_string(options)
63
+ ".with_options(#{inspect_hash_as_ruby(options)})"
64
+ end
65
+
66
+ def inspect_hash_as_ruby(hash)
67
+ hash.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
68
+ end
44
69
  end
45
70
  end
46
71
  end
@@ -10,7 +10,7 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
10
10
  # on pages throughout the dashboard.
11
11
  def attribute_types
12
12
  {<% attributes.each do |attr| %>
13
- <%= attr %>: :<%= field_type(attr) %>,<% end %>
13
+ <%= attr %>: <%= field_type(attr) %>,<% end %>
14
14
  }
15
15
  end
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Wright
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neat
@@ -141,16 +141,19 @@ files:
141
141
  - app/views/fields/form/_belongs_to.html.erb
142
142
  - app/views/fields/form/_email.html.erb
143
143
  - app/views/fields/form/_has_many.html.erb
144
+ - app/views/fields/form/_has_one.html.erb
144
145
  - app/views/fields/form/_image.html.erb
145
146
  - app/views/fields/form/_string.html.erb
146
147
  - app/views/fields/index/_belongs_to.html.erb
147
148
  - app/views/fields/index/_email.html.erb
148
149
  - app/views/fields/index/_has_many.html.erb
150
+ - app/views/fields/index/_has_one.html.erb
149
151
  - app/views/fields/index/_image.html.erb
150
152
  - app/views/fields/index/_string.html.erb
151
153
  - app/views/fields/show/_belongs_to.html.erb
152
154
  - app/views/fields/show/_email.html.erb
153
155
  - app/views/fields/show/_has_many.html.erb
156
+ - app/views/fields/show/_has_one.html.erb
154
157
  - app/views/fields/show/_image.html.erb
155
158
  - app/views/fields/show/_string.html.erb
156
159
  - app/views/layouts/administrate/application.html.erb
@@ -161,8 +164,10 @@ files:
161
164
  - lib/administrate/engine.rb
162
165
  - lib/administrate/fields/base.rb
163
166
  - lib/administrate/fields/belongs_to.rb
167
+ - lib/administrate/fields/deferred.rb
164
168
  - lib/administrate/fields/email.rb
165
169
  - lib/administrate/fields/has_many.rb
170
+ - lib/administrate/fields/has_one.rb
166
171
  - lib/administrate/fields/image.rb
167
172
  - lib/administrate/fields/string.rb
168
173
  - lib/administrate/namespace.rb