Module: Baltix::Spec::Rpm::SpecCore
- Included in:
- Baltix::Spec::Rpm, Secondary
- Defined in:
- lib/baltix/spec/rpm/spec_core.rb
Constant Summary collapse
- URL_MATCHER =
{ /(?<proto>https?:\/\/)?(?<user>[^\.]+).github.io\/(?<page>[^\/]+)/ => ->(m) do "https://github.com/#{m["user"]}/#{m["page"]}.git" end, /(?<proto>https?:\/\/)?github.com\/(?<user>[^\/]+)\/(?<page>[^\/]+)/ => ->(m) do "https://github.com/#{m["user"]}/#{m["page"]}.git" end }
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #evr ⇒ Object
-
#executable_name ⇒ Object
executable_name
returns a name of the executable package, based on the all the sources executables. - #of_default(name) ⇒ Object
- #of_options(name) ⇒ Object
- #of_source(name) ⇒ Object
- #of_space(name) ⇒ Object
- #of_state(name) ⇒ Object
- #options ⇒ Object
- #options=(options) ⇒ Object
- #prefix ⇒ Object
- #read_attribute(name, seq = nil) ⇒ Object
- #state ⇒ Object
- #state=(value) ⇒ Object
- #summary ⇒ Object
Class Method Details
.included(obj) ⇒ Object
567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 567 def included obj obj::STATE.each do |name, opts| obj.define_method(name) { self[name] ||= read_attribute(name, opts[:seq]) || of_default(name) } #obj.define_method("_#{name}") { of_state[name] } obj.define_method("has_#{name}?") { !read_attribute(name, opts["seq"]).blank? } end %w(lib exec doc devel app).each do |name| obj.define_method("is_#{name}?") { self.kind.to_s == name } end end |
Instance Method Details
#[](name) ⇒ Object
37 38 39 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 37 def [] name instance_variable_get(:"@#{name}") end |
#[]=(name, value) ⇒ Object
41 42 43 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 41 def []= name, value instance_variable_set(:"@#{name}", value) end |
#evr ⇒ Object
80 81 82 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 80 def evr "#{epoch ? "#{epoch}:" : ""}#{version}-#{release}" end |
#executable_name ⇒ Object
executable_name
returns a name of the executable package, based on the all the sources executables.
spec.executable_name # => foo
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 93 def executable_name # TODO make smart selection of executable name @executable_name = if executables.size > 1 max = executables.map { |x| x.size }.max exec_map = executables.map {|exec| (exec + " " * (max - exec.size)).unpack("U*") } filter = [45, 46, 95] exec_map.transpose.reverse.reduce([]) do |r, chars| if (chars | filter).size == chars.size || ([ chars.first ] | chars).size == 1 r.concat([ chars.first ]) else [] end end.reverse.pack("U*") else executables.first&.gsub(/[_\.]/, '-') || "" end end |
#of_default(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 31 def of_default name default = self.class::STATE[name][:default] default.is_a?(Proc) ? default[self] : default end |
#of_options(name) ⇒ Object
23 24 25 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 23 def name [name] end |
#of_source(name) ⇒ Object
13 14 15 16 17 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 13 def of_source name source.send(name) || nil rescue NameError nil end |
#of_space(name) ⇒ Object
27 28 29 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 27 def of_space name space.respond_to?(name) ? space.send(name) : nil end |
#of_state(name) ⇒ Object
19 20 21 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 19 def of_state name state[name.to_s] || state[name.to_sym] end |
#options ⇒ Object
64 65 66 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 64 def @options ||= {}.to_os end |
#options=(options) ⇒ Object
60 61 62 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 60 def @options = .to_os end |
#prefix ⇒ Object
113 114 115 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 113 def prefix name.class.default_prefix end |
#read_attribute(name, seq = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 45 def read_attribute name, seq = nil aa = (seq || self.class::STATE[name][:seq]).reduce(nil) do |value_in, func| # binding.pry if name == :context if func[0] == "_" send(func, value_in) elsif value_in.blank? send(func, name) else value_in end end # binding.pry if name == :context aa end |
#state ⇒ Object
68 69 70 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 68 def state @state ||= {}.to_os end |
#state=(value) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 72 def state= value if value.name @name = name.merge(value.name) end @state = value.to_os end |
#summary ⇒ Object
84 85 86 |
# File 'lib/baltix/spec/rpm/spec_core.rb', line 84 def summary summaries[Baltix::I18n.default_locale] end |