Class: Microscope::InstanceMethod
- Inherits:
-
Struct
- Object
- Struct
- Microscope::InstanceMethod
- Defined in:
- lib/microscope/instance_method.rb,
lib/microscope/instance_method/date_instance_method.rb,
lib/microscope/instance_method/boolean_instance_method.rb,
lib/microscope/instance_method/datetime_instance_method.rb
Direct Known Subclasses
BooleanInstanceMethod, DateInstanceMethod, DatetimeInstanceMethod
Defined Under Namespace
Classes: BooleanInstanceMethod, DateInstanceMethod, DatetimeInstanceMethod
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#model ⇒ Object
Returns the value of attribute model.
Class Method Summary collapse
-
.inject_instance_methods(model, fields, options = {}) ⇒ Object
Inject ActiveRecord scopes into a model.
-
.past_participle_to_infinitive(key) ⇒ Object
Convert a past participle to its infinitive form.
-
.value_to_boolean(value) ⇒ Object
Convert a value to its boolean representation.
Instance Method Summary collapse
- #cropped_field ⇒ Object
-
#initialize(*args) ⇒ InstanceMethod
constructor
A new instance of InstanceMethod.
Constructor Details
#initialize(*args) ⇒ InstanceMethod
Returns a new instance of InstanceMethod.
3 4 5 6 |
# File 'lib/microscope/instance_method.rb', line 3 def initialize(*args) super @field_name = field.name end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field
2 3 4 |
# File 'lib/microscope/instance_method.rb', line 2 def field @field end |
#model ⇒ Object
Returns the value of attribute model
2 3 4 |
# File 'lib/microscope/instance_method.rb', line 2 def model @model end |
Class Method Details
.inject_instance_methods(model, fields, options = {}) ⇒ Object
Inject ActiveRecord scopes into a model
13 14 15 16 17 18 19 20 21 |
# File 'lib/microscope/instance_method.rb', line 13 def self.inject_instance_methods(model, fields, = {}) fields.each do |field| scope = "#{field.type.to_s.camelize}InstanceMethod" if Microscope::InstanceMethod.const_defined?(scope) "Microscope::InstanceMethod::#{scope}".constantize.new(model, field).apply end end end |
.past_participle_to_infinitive(key) ⇒ Object
Convert a past participle to its infinitive form
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/microscope/instance_method.rb', line 24 def self.past_participle_to_infinitive(key) *key, participle = key.split('_') infinitive = if Microscope.irregular_verbs.include?(participle) Microscope.irregular_verbs[participle] elsif participle =~ /ed$/ participle.sub(/d$/, '') else participle end (key << infinitive).join('_') end |
.value_to_boolean(value) ⇒ Object
Convert a value to its boolean representation
39 40 41 |
# File 'lib/microscope/instance_method.rb', line 39 def self.value_to_boolean(value) ![nil, false, 0, '0', 'f', 'F', 'false', 'FALSE'].include?(value.presence) end |
Instance Method Details
#cropped_field ⇒ Object
8 9 10 |
# File 'lib/microscope/instance_method.rb', line 8 def cropped_field @cropped_field ||= @field_name.gsub(@cropped_field_regex, '') end |