Class: Optimacms::Resource
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Optimacms::Resource
- Defined in:
- app/models/optimacms/resource.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.method_missing(method_sym, *arguments, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/models/optimacms/resource.rb', line 22 def self.method_missing(method_sym, *arguments, &block) # the first argument is a Symbol, so you need to_s it if you want to pattern match #if method_sym.to_s =~ /^find_by_(.*)$/ v(method_sym.to_s) #else # super #end end |
.v(name) ⇒ Object
17 18 19 |
# File 'app/models/optimacms/resource.rb', line 17 def self.v(name) where(name: name).first.content rescue '' end |
Instance Method Details
#get_usages ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/optimacms/resource.rb', line 32 def get_usages res = [] dd = Rails.root.join('app', 'views') Dir.glob("#{dd}/**/*").each do |f| r = {} next if File.directory?(f) r[:path] = f r[:shortpath] = f.gsub(/#{dd}\/?/,'') # find in file hits = [] File.foreach(f).with_index do |s, line_ind| #puts "#{line_num}: #{line}" if s[/msg\.#{name}/] hits << {line: s, line_ind: line_ind} end end r[:hits] = hits if hits.count > 0 # find template tp = r[:shortpath].gsub(/\.html\.(haml|erb)$/, '') tp.gsub! /\/_/, '/' row_template = Optimacms::Template.where(:basepath=>tp).first if row_template r[:template_id] = row_template.id end res << r end end res end |