Sha256: 93271d94c6f29954620252196bde8a1272e06a6a0001f778630585732d9d1b16
Contents?: true
Size: 964 Bytes
Versions: 1
Compression:
Stored size: 964 Bytes
Contents
module Microscope class InstanceMethod < Struct.new(:model, :field) # Inject ActiveRecord scopes into a model def self.inject_instance_methods(model, fields, options = {}) 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 # Convert a past participle to its infinitive form def self.past_participle_to_infinitive(participle) if Microscope.irregular_verbs.include?(participle) Microscope.irregular_verbs[participle] elsif participle =~ /ed$/ participle.sub(/d$/, '') else participle end end # Convert a value to its boolean representation def self.value_to_boolean(value) ![nil, false, 0, '0', 'f', 'F', 'false', 'FALSE'].include?(value.presence) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
microscope-0.5.3 | lib/microscope/instance_method.rb |