rafters 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: 20c5adf484fe6dee7a436bf120a01abc45262768
4
- data.tar.gz: 492d4021eb8760ea3d0a1da556c31a0b9bd3c2ef
3
+ metadata.gz: e8b3844cb042af682eebe4144d1b7fc4ec2c94f4
4
+ data.tar.gz: a8289294a9c4738ac9d32d6196341943975cadf1
5
5
  SHA512:
6
- metadata.gz: d55783f2ff80d38f75990f1a82b3a04d48d8a18f1c0026cb7dbd5adcded1afdc7c4218dd58a936a5aac9ab0cf0e2d033a865eab6071eba75549930ecdada9cd3
7
- data.tar.gz: 16d62a56843a39b954b94438b7e6c29d0cc7c051b932d55507468daea22442440a743fbb5f0d8644b5d2befb8b9b3e4c0e6c4123729e7986498ce80049a13ee6
6
+ metadata.gz: 72dc85e535552dd97e66455a060c6177f6e9877e3172e5e6f2509947e0cbf9d3aeb16c674596075d1112eff71c88b1d9db20eb7f1c59f24b035f3937cff72235
7
+ data.tar.gz: f28a3aa42f3d4a0fc9e9c2a70106a864377b93388e829c9a2cbdfaf5c0b581a4c783fce4f96bc41bc669ca702b5ecda11b61831ef2487dd8c234980c4ade613c
data/README.md CHANGED
@@ -98,6 +98,43 @@ You can access the attribute in your component view using the `attributes` objec
98
98
  <h1><%= attributes.title %></h1>
99
99
  </div>
100
100
  ```
101
+
102
+ ### Accessing information from the controller in your components
103
+
104
+ There will often be times when you need to access data in your component that is only available as an instance variable or method in your controller. Rafters provides a convenience method that lets you get to that data in a uniform way - `Rafters::Component#current`:
105
+
106
+ ```ruby
107
+ class PostController
108
+ ...
109
+
110
+ def show
111
+ @post = current_user.posts.find(params[:id])
112
+ end
113
+
114
+ private
115
+
116
+ def current_user
117
+ @current_user ||= User.authenticate!(...)
118
+ end
119
+ helper_method :current_user
120
+ end
121
+ ```
122
+
123
+ ```ruby
124
+ class RelatedPostsComponent
125
+ ...
126
+
127
+ def related_posts
128
+ @related_posts ||= current(:post).related_posts.where(author_id: current(:current_user))
129
+ end
130
+ end
131
+ ```
132
+
133
+ You can also access the controller's params using this method:
134
+
135
+ ```ruby
136
+ current(:params)[:id]
137
+ ```
101
138
 
102
139
  ### Adding a setting to a component
103
140
 
@@ -40,7 +40,7 @@ module Rafters::Component
40
40
  def current(variable_or_method_name)
41
41
  if @controller.instance_variable_defined?("@#{variable_or_method_name}")
42
42
  @controller.instance_variable_get("@#{variable_or_method_name}")
43
- elsif @controller.respond_to?(variable_or_method_name)
43
+ elsif @controller.respond_to?(variable_or_method_name, true)
44
44
  @controller.send(variable_or_method_name)
45
45
  else
46
46
  raise CurrentVariableOrMethodNameMissing
@@ -1,3 +1,3 @@
1
1
  module Rafters
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/rafters.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.1"
24
24
  spec.add_development_dependency "rspec-rails", "~> 2.14"
25
25
 
26
- spec.add_dependency "rails", "~> 4.0.0"
26
+ spec.add_dependency "rails", "> 3.2"
27
27
  spec.add_dependency "hashie", "~> 2.0.5"
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rafters
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
  - Andrew Hite
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - '>'
74
74
  - !ruby/object:Gem::Version
75
- version: 4.0.0
75
+ version: '3.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - '>'
81
81
  - !ruby/object:Gem::Version
82
- version: 4.0.0
82
+ version: '3.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: hashie
85
85
  requirement: !ruby/object:Gem::Requirement