active_admin_simple_life 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a2dbffd025fcc68736c506d897440a46c2267c0
4
- data.tar.gz: 9ebceb079da704c2ef06c17e859a9fd8f95f3ae9
3
+ metadata.gz: 4dbb9fd0eac672fd2b9f57ca4243839719b16c7c
4
+ data.tar.gz: a6f3c276440b9b8a69294745b256d47d2b1b240a
5
5
  SHA512:
6
- metadata.gz: 5bde864d944472b403a1c6e88d6d83c8c15e3820bd447b4f10ea6e342a30349cae4c22c81c567d66bd5fdbc8082a023daaa6abeb88c265a5b78036baf8b67857
7
- data.tar.gz: 4fd154aebd08ccbfafa57bb6f9ca086160036d0065c0909d4af113966ac4075f25224452961801be7276b97ec6626db72bb5ebd1d7175a9747bf28c1ed7c9588
6
+ metadata.gz: b737608ba11584d5e318e575b0e8c1655c2d1a850589b66e834e4a2a8c4ee552e524757f8005e9bd8909e0c76a0df921fc7cc9876fdd9c9bc5ab825e1dc46fb5
7
+ data.tar.gz: 433b2308c7da1455bad83e00addb86a0e7b23e369ba1978c8f072015aeb2a91a42f4dd7a3ea09d86bc71b1fd2262e77a1aec21855c48c9b5a270dceaa8b5a358
data/README.md CHANGED
@@ -56,6 +56,13 @@ Parts of `simple_menu_for` may be used for other purposes with:
56
56
  Other feature is simple menu with 1 single nested klass. For it I made
57
57
  * `nested_form_for_main_fields klass, nested_klass`
58
58
 
59
+ ###Goodies
60
+
61
+ Added generator with simple settings model for future use. I find it reusable,
62
+ so, you may like it. For installation run
63
+
64
+ `rails g active_admin_simple_life:simple_config`
65
+
59
66
  ###I18n
60
67
 
61
68
  For boolean data only
@@ -66,3 +73,8 @@ en:
66
73
  active: 'Active'
67
74
  not_active: 'Not active'
68
75
  ```
76
+
77
+ ###PS:
78
+ After making this gem a found this
79
+ [article](http://tmichel.github.io/2015/02/22/sharing-code-between-activeadmin-resources/),
80
+ it may be useful.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveAdminSimpleLife
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ require "rails/generators"
3
+ module ActiveAdminSimpleLife
4
+ class SimpleConfigGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ desc "Generates simple configuration table for active_admin"
8
+
9
+ def generate_migration
10
+ run "rails g model config title:string internal_name:string:index configurable:references{polymorphic} primitive:string:true"
11
+ end
12
+
13
+ def copy_model_file
14
+ remove_file "app/models/config.rb"
15
+ copy_file "config_model.rb", "app/models/config.rb"
16
+ end
17
+
18
+ def copy_admin_file
19
+ copy_file "config_admin.rb", "app/admin/config.rb"
20
+ end
21
+
22
+ def add_lib_dir
23
+ copy_file "require_lib.rb", "config/initializers/require_lib.rb"
24
+ end
25
+
26
+ def extend_array_method
27
+ copy_file "array.rb", "lib/array.rb"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ class Array
3
+ def fetch_all_objects_from_klasses
4
+ inject([]) do |a, klass|
5
+ a << klass.all.map do |object|
6
+ [I18n.t("activerecord.singular_models.#{klass.to_s.underscore}") + " - #{object}",
7
+ "#{object.class}##{object.id}"]
8
+ end
9
+ end.flatten(1)
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ ActiveAdmin.register Config do
3
+ menu priority: 10
4
+ permit_params(*(Config.main_fields + [:configurable_identifier]))
5
+ actions :all, except: [:show]
6
+
7
+ index do
8
+ selectable_column
9
+ id_column
10
+ [:title, :internal_name].each { |field| column field }
11
+ column :configurable do |c|
12
+ if c.configurable
13
+ link_to I18n.t("activerecord.models.#{c.configurable_type.underscore}") + " - #{c.configurable}",
14
+ [:admin, c.configurable]
15
+ else
16
+ c.primitive
17
+ end
18
+ end
19
+ actions
20
+ end
21
+
22
+ [:title, :internal_name].each { |f| filter f }
23
+
24
+ # Inject needed classes here, which will be listed in select
25
+ # object_list = [Foo, Bar, Baz]
26
+ object_list = []
27
+
28
+ form do |f|
29
+ f.semantic_errors(*f.object.errors.keys)
30
+ f.inputs do
31
+ f.input :title
32
+ f.input :internal_name
33
+ f.input :configurable_identifier,
34
+ collection: object_list.fetch_all_objects_from_klasses,
35
+ value: "#{resource.class}##{resource.id}"
36
+ f.input :primitive
37
+ end
38
+ f.actions
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ class Config < ActiveRecord::Base
3
+ belongs_to :configurable, polymorphic: true
4
+ validates :title, :internal_name, presence: true
5
+ validates :title, :internal_name, uniqueness: true
6
+
7
+ attr_accessor :configurable_identifier
8
+
9
+ def self.main_fields
10
+ [:title, :internal_name, :configurable, :primitive]
11
+ end
12
+
13
+ def configurable_identifier
14
+ "#{configurable_type}##{configurable_id}"
15
+ end
16
+
17
+ def configurable_identifier=(data)
18
+ if data.present?
19
+ config_data = data.split('#')
20
+ self.configurable_type = config_data[0]
21
+ self.configurable_id = config_data[1]
22
+ else
23
+ self.configurable_type = nil
24
+ self.configurable_id = nil
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ Dir[Rails.root.join("lib/*.rb")].each { |file| require file }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_simple_life
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kvokka
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.0
27
- - !ruby/object:Gem::Dependency
28
- name: activeadmin
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  description: This gem provide the ability to create ActiveAdmin resourceswith 1 line
42
28
  and avoid code duplication.
43
29
  email:
@@ -56,6 +42,11 @@ files:
56
42
  - lib/active_admin_simple_life/menu_elements.rb
57
43
  - lib/active_admin_simple_life/simple_menu.rb
58
44
  - lib/active_admin_simple_life/version.rb
45
+ - lib/generators/active_admin_simple_life/simple_config_generator.rb
46
+ - lib/generators/active_admin_simple_life/templates/array.rb
47
+ - lib/generators/active_admin_simple_life/templates/config_admin.rb
48
+ - lib/generators/active_admin_simple_life/templates/config_model.rb
49
+ - lib/generators/active_admin_simple_life/templates/require_lib.rb
59
50
  - lib/tasks/active_admin_simple_life_tasks.rake
60
51
  homepage: https://github.com/kvokka/active_admin_simple_life
61
52
  licenses: