databrowser 1.0 → 1.0.1

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.
Files changed (2) hide show
  1. data/lib/data_browser/helpers.rb +36 -0
  2. metadata +2 -1
@@ -0,0 +1,36 @@
1
+ module DataBrowser
2
+ module Helpers
3
+ def self.included(base)
4
+ base.send :helper_method, :current_model, :current_object, :current_model_id, :object_params
5
+ end
6
+
7
+ def current_model
8
+ @model ||= DataBrowser.models[current_model_id] if current_model_id
9
+ end
10
+
11
+ def current_object
12
+ @obj ||= if params[:id] && !params[:id].eql?("x")
13
+ current_model.find(params[:id])
14
+ elsif params[:object]
15
+ current_model.first :conditions => params[:object]
16
+ else
17
+ current_model.new
18
+ end
19
+ end
20
+
21
+ def current_model_id
22
+ params[:model].to_i if params[:model]
23
+ end
24
+
25
+ def object_params(object)
26
+ params = {:model => current_model_id}
27
+ if object.to_param
28
+ params[:id] = object.to_param
29
+ else
30
+ params[:id] = "x"
31
+ params[:object] = object.attributes
32
+ end
33
+ params
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: databrowser
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Junior
@@ -42,6 +42,7 @@ files:
42
42
  - lib/data_browser/data_browser.rb
43
43
  - lib/data_browser/data_browser_controller.rb
44
44
  - lib/data_browser/routing.rb
45
+ - lib/data_browser/helpers.rb
45
46
  - lib/data_browser/views/data_browser/data_browser/about.html.erb
46
47
  - lib/data_browser/views/data_browser/data_browser/browse.html.erb
47
48
  - lib/data_browser/views/data_browser/data_browser/browse.js.rjs