active_admin_associations 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0eef05dc7ab13e1962ed5bb40a13d6ac259a8883
4
+ data.tar.gz: 53a5c209fb1b39f1c9c3fbe24cf7e77154d3a035
5
+ SHA512:
6
+ metadata.gz: 56bc52415b2871ec55d4e7bcdba5217ce4a5e2ea46e8f2cc64d9e3000337c5b7c13c8f6bed0f93a758331f43381202db7fcd4a1c15b99bd2758b53aa75885fc5
7
+ data.tar.gz: 6675073a7d39ae6ff44d2733f039760995ba29c04eaa63f4eea23de952aad2c1b16caa3f15508bbb35586d17cdd86ef6ba8aa9c18a30b64f01229083ac661804
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_admin_associations.gemspec
4
+ gemspec
@@ -0,0 +1,43 @@
1
+ # ActiveAdminAssociations
2
+
3
+ A dropdown menu for your ActiveRecord relations between ActiveAdmin Resources.
4
+
5
+ ## Notes
6
+
7
+ Only builds properly for `has_many` associations right now because I assume you're already direcly linking to the appropriate resource for `belongs_to` with Arbre.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'active_admin_associations'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install active_admin_associations
24
+
25
+ ## Usage
26
+
27
+ This is pretty opinionated right now.
28
+
29
+ In a resource file in an ActiveAdmin namespace, open `user.rb` and add `has_many :orders` inside the `register` block. This will create an `action_item` for the show/edit actions that renders a dropdown menu with a link to the Orders associated with the current resource ID.
30
+
31
+ Add `association_items` anywhere on the resource page to display the dropdown.
32
+
33
+ This does not do anything else. It does not mean to do anything else. It doesn't hit ActiveRecord or check to see that your `Order` resource actually exists inside ActiveAdmin. It simply builds a link to the assumed Ransack query URL.
34
+
35
+ ### Options
36
+
37
+ Use `as` to change the label. Defaults to `class.model_name.plural`
38
+
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joshmn/active_admin_associations.
43
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin_associations/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_admin_associations"
8
+ spec.version = ActiveAdminAssociations::VERSION
9
+ spec.authors = ["Josh Brody"]
10
+ spec.email = ["josh@josh.mn"]
11
+
12
+ spec.summary = %q{A dropdown menu for your ActiveRecord relations between ActiveAdmin Resources.}
13
+ spec.description = %q{A dropdown menu for your ActiveRecord relations between ActiveAdmin Resources.}
14
+ spec.homepage = "https://github.com/joshmn/active_admin_associations"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency "activeadmin", "> 0.6.0"
27
+ spec.add_dependency "rails", "> 3.0.0"
28
+
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_admin_associations"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ require 'active_admin'
2
+ require 'active_admin_associations/association'
3
+ require 'active_admin_associations/resource_dsl'
4
+ require 'active_admin_associations/active_admin/resource/associations'
5
+
6
+ require "active_admin_associations/version"
7
+
8
+ module ActiveAdminAssociations
9
+ module Rails
10
+ class Engine < ::Rails::Engine
11
+ config.after_initialize do
12
+ ::ActiveAdmin::ResourceDSL.send(:include, ActiveAdminAssociations::ResourceDSL)
13
+ ::ActiveAdmin::Resource.send(:include, ActiveAdminAssociations::ActiveAdmin::Resource::Associations)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveAdminAssociations
2
+ module ActiveAdmin
3
+ class Resource
4
+ module Associations
5
+ def associations
6
+ @associations ||= []
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module ActiveAdminAssociations
2
+ class Association
3
+
4
+ attr_reader :name, :options
5
+ def initialize(name, options = {})
6
+ @name = name
7
+ @options = options.symbolize_keys
8
+ set_default_options
9
+ end
10
+
11
+ def label
12
+ @options[:as]
13
+ end
14
+
15
+ private
16
+
17
+ def set_default_options
18
+ @options[:as] ||= name.to_s.classify.constantize.model_name.plural.titleize
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ module ActiveAdminAssociations
2
+ module ResourceDSL
3
+
4
+ private
5
+
6
+ def has_many(name, options = {})
7
+ config.associations << ActiveAdminAssociations::Association.new(name, options)
8
+
9
+ end
10
+
11
+ def association_items
12
+ return nil if config.associations.empty?
13
+ resource_associations = config.associations
14
+ current_namespace = config.namespace.name
15
+ config.add_action_item("Associations", :except => [:index, :new]) do
16
+ dropdown_menu "Associations" do
17
+ resource_associations.each do |association|
18
+ item association.label, [current_namespace, association.name, "q[#{resource.model_name.param_key}_id_equals]".to_sym => resource.to_param]
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminAssociations
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_associations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Brody
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activeadmin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ description: A dropdown menu for your ActiveRecord relations between ActiveAdmin Resources.
70
+ email:
71
+ - josh@josh.mn
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - active_admin_associations.gemspec
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/active_admin_associations.rb
84
+ - lib/active_admin_associations/active_admin/resource/associations.rb
85
+ - lib/active_admin_associations/association.rb
86
+ - lib/active_admin_associations/resource_dsl.rb
87
+ - lib/active_admin_associations/version.rb
88
+ homepage: https://github.com/joshmn/active_admin_associations
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.13
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A dropdown menu for your ActiveRecord relations between ActiveAdmin Resources.
111
+ test_files: []