Class: Fencepost::Fencepost
- Inherits:
-
Object
- Object
- Fencepost::Fencepost
- Defined in:
- lib/fencepost/fencepost.rb
Instance Attribute Summary collapse
-
#gate ⇒ Object
readonly
Returns the value of attribute gate.
Class Method Summary collapse
Instance Method Summary collapse
- #allow(elements) ⇒ Object
- #deny(elements) ⇒ Object
- #ensure_models ⇒ Object
-
#initialize(params) ⇒ Fencepost
constructor
A new instance of Fencepost.
Constructor Details
#initialize(params) ⇒ Fencepost
Returns a new instance of Fencepost.
5 6 7 8 9 10 11 12 13 |
# File 'lib/fencepost/fencepost.rb', line 5 def initialize(params) ensure_models @gate = Gate.new(self.class.model_list, params) self.class.models.each do |model| define_singleton_method self.class.method_name(model) do gate.open(params, self.class.param_key(model), model) end end end |
Instance Attribute Details
#gate ⇒ Object (readonly)
Returns the value of attribute gate
3 4 5 |
# File 'lib/fencepost/fencepost.rb', line 3 def gate @gate end |
Class Method Details
.generate_model_list ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fencepost/fencepost.rb', line 19 def self.generate_model_list model_list = {} models.each do |model| model_list[self.param_key(model)] = { model: model, attributes: self.attribute_keys(model), demodulized_name: self.demodulized_name(model), nested_collection_name: self.nested_collection_name(model), nested_attributes_name: self.nested_attributes_name(model), nested_attributes_options: self.(model), nested_singular_name: self.nested_singular_attributes_name(model) } end model_list end |
.models ⇒ Object
15 16 17 |
# File 'lib/fencepost/fencepost.rb', line 15 def self.models ActiveRecord::Base.descendants - [ActiveRecord::SchemaMigration] end |
Instance Method Details
#allow(elements) ⇒ Object
45 46 47 48 |
# File 'lib/fencepost/fencepost.rb', line 45 def allow(elements) gate.allow(elements) self end |
#deny(elements) ⇒ Object
50 51 52 53 |
# File 'lib/fencepost/fencepost.rb', line 50 def deny(elements) gate.deny(elements) self end |
#ensure_models ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/fencepost/fencepost.rb', line 37 def ensure_models klass = self.class if ::Fencepost.configuration.dev_mode Rails.application.eager_load! klass.model_list = klass.generate_model_list end end |