Module: Netzke::ActiveRecord::Attributes::ClassMethods
- Defined in:
- lib/netzke/active_record/attributes.rb
Instance Method Summary collapse
- #data_adapter ⇒ Object
-
#netzke_attribute(name, options = {}) ⇒ Object
Define or configure an attribute.
- #netzke_attribute_hash ⇒ Object
-
#netzke_attributes ⇒ Object
Returns the attributes that will be picked up by grids and forms.
-
#netzke_exclude_attributes(*args) ⇒ Object
Exclude attributes from being picked up by grids and forms.
-
#netzke_expose_attributes(*args) ⇒ Object
Explicitly expose attributes that should be picked up by grids and forms.
- #netzke_exposed_attributes ⇒ Object
Instance Method Details
#data_adapter ⇒ Object
17 18 19 |
# File 'lib/netzke/active_record/attributes.rb', line 17 def data_adapter @data_adapter = Netzke::Basepack::DataAdapters::AbstractAdapter.adapter_class(self).new(self) end |
#netzke_attribute(name, options = {}) ⇒ Object
Define or configure an attribute. Example:
netzke_attribute :recent, :type => :boolean, :read_only => true
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/netzke/active_record/attributes.rb', line 24 def netzke_attribute(name, = {}) name = name.to_s [:attr_type] = .delete(:type) || .delete(:attr_type) || :string declared_attrs = self.netzke_declared_attr.dup # if the attr was declared already, simply merge it with the new options existing = declared_attrs.detect{ |va| va[:name] == name } if existing existing.merge!() else attr_config = {:name => name}.merge() # if primary_key, insert in front, otherwise append if name == self.primary_key declared_attrs.insert(0, attr_config) else declared_attrs << {:name => name}.merge() end end self.netzke_declared_attr = declared_attrs end |
#netzke_attribute_hash ⇒ Object
67 68 69 |
# File 'lib/netzke/active_record/attributes.rb', line 67 def netzke_attribute_hash netzke_attributes.inject({}){ |r,a| r.merge(a[:name].to_sym => a) } end |
#netzke_attributes ⇒ Object
Returns the attributes that will be picked up by grids and forms.
62 63 64 65 |
# File 'lib/netzke/active_record/attributes.rb', line 62 def netzke_attributes exposed = netzke_exposed_attributes exposed ? netzke_attrs_in_forced_order(exposed) : netzke_attrs_in_natural_order end |
#netzke_exclude_attributes(*args) ⇒ Object
Exclude attributes from being picked up by grids and forms. Accepts an array of attribute names (as symbols). Example:
netzke_expose_attributes :created_at, :updated_at, :crypted_password
48 49 50 |
# File 'lib/netzke/active_record/attributes.rb', line 48 def netzke_exclude_attributes(*args) self.netzke_excluded_attr = args.map(&:to_s) end |
#netzke_expose_attributes(*args) ⇒ Object
Explicitly expose attributes that should be picked up by grids and forms. Accepts an array of attribute names (as symbols). Takes precedence over netzke_exclude_attributes
. Example:
netzke_expose_attributes :name, :role__name
57 58 59 |
# File 'lib/netzke/active_record/attributes.rb', line 57 def netzke_expose_attributes(*args) self.netzke_exposed_attr = args.map(&:to_s) end |
#netzke_exposed_attributes ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/netzke/active_record/attributes.rb', line 71 def netzke_exposed_attributes exposed = self.netzke_exposed_attr if exposed && !exposed.include?(self.primary_key) # automatically declare primary key as a netzke attribute netzke_attribute(self.primary_key) exposed.insert(0, self.primary_key) end exposed end |